EEVblog Electronics Community Forum
Electronics => Microcontrollers => Topic started by: david-electrical on May 27, 2016, 09:37:53 am
-
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);
}
}
-
1st thing 1st.. make proper indentation...
-
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);
}
}
-
I think line 44, which is:
if (notes == '')
should instead be this:
if (notes[i] == '')
Same issue on line 25 as well
if (names[i] == note)
Edit: And line 47
playNote(notes[i], beats*tempo);
Edit: and there is another one too, but you can find that one :)
-
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.
-
music fire alarm
That's an interesting innovation we can live without: soothing and comforting music when the fire is raging.
-
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?
-
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.
-
just a suggestion...
https://www.youtube.com/watch?v=sbbYPqgSe-M (https://www.youtube.com/watch?v=sbbYPqgSe-M)
(ps: i'd be surprised if someone come edit this post saying this is a weird and dangerous advice...)
-
Oh lol. Yes, i meant "good"
But that's hilarious :-DD
-
just a suggestion...
https://www.youtube.com/watch?v=sbbYPqgSe-M (https://www.youtube.com/watch?v=sbbYPqgSe-M)
(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
-
The "empty character constant" message comes from code like this:
a = '';
Note that there isn't a character inside the single-quotes. That's not allowed in C.
In your code:
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?