Hi,
so, I am making a program which will flash different lights every time a different note is played (trying to play happy birthday). I keep getting the same errors and I have no idea how to fix them. Please help me.
This is my code:
And these are my errors:
Please help me. I would really appreciate it
so, I am making a program which will flash different lights every time a different note is played (trying to play happy birthday). I keep getting the same errors and I have no idea how to fix them. Please help me.
This is my code:
Code:
int piezo = 8;
int ledrood = 2;
int ledgeel = 4;
int ledgroen = 7;
int ledblauw = 12;
int ledwit = 13;
int tweekeerlied = 50;
char namen[] = {'A','B','C','D','E','F','G'};
int tonen[] = {440, 493, 262, 294, 330, 349, 392};
char noten[] = {"GGAGCBGGAGDCGGGECBAFFECDC"};
int ritme[] = {3,2,2,2,2,4,3,2,2,2,2,3,2,2,2,2,2,2,3,2,2,2,2,4};
int tempo = 100;
void setup() {
pinMode(piezo,OUTPUT);
pinMode(ledwit, OUTPUT);
pinMode(ledblauw, OUTPUT);
pinMode(ledgroen, OUTPUT);
pinMode(ledgeel, OUTPUT);
pinMode(ledrood, OUTPUT);
}
void loop() {
int i, lengte;
for (i=0; i < tweekeerlied; i++)
{lengte = ritme[i] * tempo;
{if (noten[i] = ' ')
{delay = lengte;}
else {
tone(piezo, tonen(noten[i]), lengte);
if((tonen(noten[i]) = 392) || (tonen(noten[i]) = 440))
{digitalWrite(ledrood, HIGH);
delay(lengte);}
else if ((tonen(noten[i]) = 349) || (tonen(noten[i]) = 493))
{digitalWrite(ledgeel, HIGH);
delay(lengte);}
else if (tonen(noten[i]) = 330)
{digitalWrite(ledgroen, HIGH);
delay(lengte);}
else if ((tonen(noten[i]) = 294) || (tonen(noten[i]) = 440) || (tonen(noten[i]) = 493))
{digitalWrite(ledblauw, HIGH);
delay(lengte);}
else if (tonen(noten[i]) = 262)
{digitalWrite(ledwit, HIGH);
delay(lengte);};
}
}
digitalWrite(ledrood, LOW);
digitalWrite(ledgeel, LOW);
digitalWrite(ledgroen, LOW);
digitalWrite(ledblauw, LOW);
digitalWrite(ledwit, LOW);
delay(tempo/2);
}
while(true)
{noTone(piezo);
digitalWrite(ledrood, LOW);
digitalWrite(ledgeel, LOW);
digitalWrite(ledgroen, LOW);
digitalWrite(ledblauw, LOW);
digitalWrite(ledwit, LOW);
}
{int ritme(char noten)
{int i;
int notenaantal = 7;
for(i=0;i<notenaantal;i++)
{if (namen[i] == noten)
{return(ritme[i]);}
else {return(0)}
}
}
}
And these are my errors:
Code:
In function 'void loop()':
29:12: error: assignment of function 'void delay(long unsigned int)'
{delay = lengte;}
^~~~~~
29:12: error: cannot convert 'int' to 'void(long unsigned int)' in assignment
31:32: error: 'tonen' cannot be used as a function
tone(piezo, tonen(noten[i]), lengte);
^
32:26: error: 'tonen' cannot be used as a function
if((tonen(noten[i]) = 392) || (tonen(noten[i]) = 440))
^
32:53: error: 'tonen' cannot be used as a function
if((tonen(noten[i]) = 392) || (tonen(noten[i]) = 440))
^
35:30: error: 'tonen' cannot be used as a function
else if ((tonen(noten[i]) = 349) || (tonen(noten[i]) = 493))
^
35:57: error: 'tonen' cannot be used as a function
else if ((tonen(noten[i]) = 349) || (tonen(noten[i]) = 493))
^
38:38: error: 'tonen' cannot be used as a function
else if (tonen(noten[i]) = 330)
^
41:39: error: 'tonen' cannot be used as a function
else if ((tonen(noten[i]) = 294) || (tonen(noten[i]) = 440) || (tonen(noten[i]) = 493))
^
41:66: error: 'tonen' cannot be used as a function
else if ((tonen(noten[i]) = 294) || (tonen(noten[i]) = 440) || (tonen(noten[i]) = 493))
^
41:93: error: 'tonen' cannot be used as a function
else if ((tonen(noten[i]) = 294) || (tonen(noten[i]) = 440) || (tonen(noten[i]) = 493))
^
44:29: error: 'tonen' cannot be used as a function
else if (tonen(noten[i]) = 262)
^
66:15: error: a function-definition is not allowed here before '{' token
{int i;
^
74:1: error: expected '}' at end of input
}
^
exit status 1
assignment of function 'void delay(long unsigned int)'
Please help me. I would really appreciate it
Comment