Author Topic: how to solve the code problem when i made music Fire alarm by arduino?  (Read 4200 times)

0 Members and 1 Guest are viewing this topic.

Offline david-electricalTopic starter

  • Newbie
  • Posts: 6
  • Country: hk
    • Ui3g
When i made music fire alarm by arduino,i met a problem,the errow shows: empty character constant

the sensor perception the fire,then ARDUINO control buzzer,when fire closer then music to alarm

int flame=A5;
int Beep=9;
int length=15;
char notes[]="ccggaagffeeddc ";
int beats[]={1,1,1,1,1,1,2,1,1,1,1,1,1,2,4};
int tempo=300;

int val=0;
void playTone(int tone ,int duration)
{
for(long i=0;i<duration*1000L;i+=tone*2) {
digitalWrite(Beep,HIGH);
delayMicroseconds(tone);
digitalWrite(Beep,LOW);
delayMicroseconds(tone);
}
}
void playNote(char note,int duration )
{
char names[]={'c','d','e','f','g','a','b','C'};
int tones[]={1915,1700,1519,1432,1275,1136,1014,956};
for(int i=0;i<8;i++)
{
  if(names==note)
playTone(tones,duration);
}
}
void setup()   
{
  pinMode(Beep,OUTPUT); 
pinMode(flame,INPUT);
Serial.begin(9600);
}   
void loop() {
  val=analogRead(flame); 
Serial.println(val); 
if(val>=600) 
{ digitalWrite(Beep,HIGH);
   for(int i=0;i<length;i++)
   {
  if(notes=='')
delay(beats*tempo);
  else
  playNote(notes,beats*tempo);
  delay(tempo/2);
   }
}
else {
  digitalWrite(Beep,LOW);
     }
}


all my ideas in my blog
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11612
  • Country: my
  • reassessing directives...
1st thing 1st.. make proper indentation...
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 
The following users thanked this post: jnz

Offline obiwanjacobi

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Code: [Select]
int flame = A5;
int Beep = 9;
int length = 15;
char notes[] = "ccggaagffeeddc ";
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;

int val = 0;
void playTone(int tone, int duration)
{
    for (long i = 0; i<duration * 1000L; i += tone * 2)
    {
        digitalWrite(Beep, HIGH);
        delayMicroseconds(tone);
        digitalWrite(Beep, LOW);
        delayMicroseconds(tone);
    }
}
void playNote(char note, int duration)
{
    char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
    int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
    for (int i = 0; i<8; i++)
    {
        if (names == note)
            playTone(tones, duration);
    }
}
void setup()
{
    pinMode(Beep, OUTPUT);
    pinMode(flame, INPUT);
    Serial.begin(9600);
}
void loop()
{
    val = analogRead(flame);
    Serial.println(val);
    if (val >= 600)
    {
        digitalWrite(Beep, HIGH);
        for (int i = 0; i<length; i++)
        {
            if (notes == '')
                delay(beats*tempo);
            else
                playNote(notes, beats*tempo);
            delay(tempo / 2);
        }
    }
    else
    {
        digitalWrite(Beep, LOW);
    }
}
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline hendorog

  • Super Contributor
  • ***
  • Posts: 1617
  • Country: nz
I think line 44, which is:
Code: [Select]
if (notes == '')

should instead be this:
Code: [Select]
if (notes[i] == '')

Same issue on line 25 as well
Code: [Select]
if (names[i] == note)

Edit: And line 47
Code: [Select]
playNote(notes[i], beats*tempo);

Edit: and there is another one too, but you can find that one :)
« Last Edit: May 27, 2016, 10:41:09 am by hendorog »
 

Offline botcrusher

  • Regular Contributor
  • *
  • Posts: 192
  • Country: ca
I just want to point out that in most jurisdictions this is 100%  against fire code
even presuming your code is bullet proof, until you have it actually approved by a fire marshal / your local group residing over fire law, this is a big nope.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Quote
music fire alarm

That's an interesting innovation we can live without: soothing and comforting music when the fire is raging.
================================
https://dannyelectronics.wordpress.com/
 

Offline botcrusher

  • Regular Contributor
  • *
  • Posts: 192
  • Country: ca
Interestingly, HK fire code has a section on alarm parameters, of which one condition is that it is of a certain tone so that it remains recognisable. Making it sing a tune violates that, and removes the urgency from the alarm. Who would exit the building to a hood song?
 

Offline jnz

  • Frequent Contributor
  • **
  • Posts: 593
Who would exit the building to a hood song?

Im fairly sure you meant GOOD song... But I want to beleive you really meant hood song. In which case I look forward to the dual discussions about STM F0 vs NXP 1100 peripheral sets while making analogies to Kendrick's Maad City and Alright, or Lupe Fiasco's Prisoner 1&2, or even what "hood" means in terms of good or bad and if JCole is "hood" still despite Role Modelz being excellent or if something more oscure like Tech N9ne is "hood"-enough.

 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11612
  • Country: my
  • reassessing directives...
just a suggestion...

(ps: i'd be surprised if someone come edit this post saying this is a weird and dangerous advice...)

Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline botcrusher

  • Regular Contributor
  • *
  • Posts: 192
  • Country: ca
Oh lol. Yes, i meant "good"
But that's hilarious  :-DD
 

Offline timb

  • Super Contributor
  • ***
  • Posts: 2536
  • Country: us
  • Pretentiously Posting Polysyllabic Prose
    • timb.us
just a suggestion...

(ps: i'd be surprised if someone come edit this post saying this is a weird and dangerous advice...)

But... Don't you want to know why we keep starting fires? It's my desire! (My desire!) Danger! Danger! High Voltage! When we touch, when we kiss! Fire in the disco, fire in the disco! Fire in the...Taco Bell... Fire in the disco, fire in the gates of hell! Danger, danger! High Voltage...

https://youtu.be/2a4gyJsY0mc
Any sufficiently advanced technology is indistinguishable from magic; e.g., Cheez Whiz, Hot Dogs and RF.
 

Offline stmdude

  • Frequent Contributor
  • **
  • Posts: 479
  • Country: se
The "empty character constant" message comes from code like this:
Code: [Select]
a = '';
Note that there isn't a character inside the single-quotes. That's not allowed in C.
In your code:
Code: [Select]
if (notes == '') you're basically comparing with nothing.

That's an interesting innovation we can live without: soothing and comforting music when the fire is raging.
Music to die for/by?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf