By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,276 Members | 1,951 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,276 IT Pros & Developers. It's quick & easy.

Can someone please help me I don't know how to fix this errors include definition is

P: 1
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:
Expand|Select|Wrap|Line Numbers
  1. int piezo = 8;
  2. int ledrood = 2;
  3. int ledgeel = 4;
  4. int ledgroen = 7;
  5. int ledblauw = 12;
  6. int ledwit = 13;
  7. int tweekeerlied = 50;
  8. char namen[] = {'A','B','C','D','E','F','G'};
  9. int tonen[] = {440, 493, 262, 294, 330, 349, 392};
  10. char noten[] = {"GGAGCBGGAGDCGGGECBAFFECDC"};
  11. 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}; 
  12.  
  13. int tempo = 100;
  14.  
  15.  
  16. void setup() {
  17.   pinMode(piezo,OUTPUT);
  18.   pinMode(ledwit, OUTPUT);
  19.   pinMode(ledblauw, OUTPUT);
  20.   pinMode(ledgroen, OUTPUT);
  21.   pinMode(ledgeel, OUTPUT);
  22.   pinMode(ledrood, OUTPUT);
  23. }
  24.  
  25. void loop() {
  26.   int i, lengte;
  27.   for (i=0; i < tweekeerlied; i++)
  28.   {lengte = ritme[i] * tempo;
  29.    {if (noten[i] = ' ')
  30.   {delay = lengte;}
  31.    else {
  32.      tone(piezo, tonen(noten[i]), lengte);
  33.        if((tonen(noten[i]) = 392) || (tonen(noten[i]) = 440))
  34.        {digitalWrite(ledrood, HIGH);
  35.         delay(lengte);}
  36.      else if ((tonen(noten[i]) = 349) || (tonen(noten[i]) = 493))
  37.               {digitalWrite(ledgeel, HIGH);
  38.                delay(lengte);}
  39.               else if (tonen(noten[i]) = 330)
  40.               {digitalWrite(ledgroen, HIGH);
  41.                delay(lengte);}
  42.               else if ((tonen(noten[i]) = 294) || (tonen(noten[i]) = 440) || (tonen(noten[i]) = 493))
  43.               {digitalWrite(ledblauw, HIGH);
  44.                delay(lengte);}
  45.      else if (tonen(noten[i]) = 262)
  46.               {digitalWrite(ledwit, HIGH);
  47.                delay(lengte);};
  48.      }
  49.    }
  50.               digitalWrite(ledrood, LOW);
  51.               digitalWrite(ledgeel, LOW);
  52.               digitalWrite(ledgroen, LOW);
  53.               digitalWrite(ledblauw, LOW);
  54.               digitalWrite(ledwit, LOW);
  55.               delay(tempo/2);
  56.   }
  57.   while(true)
  58.               {noTone(piezo);
  59.                digitalWrite(ledrood, LOW);
  60.                digitalWrite(ledgeel, LOW);
  61.                digitalWrite(ledgroen, LOW);
  62.                digitalWrite(ledblauw, LOW);
  63.                digitalWrite(ledwit, LOW);
  64. }
  65.  
  66. {int ritme(char noten)
  67.               {int i;
  68.                int notenaantal = 7;
  69.                for(i=0;i<notenaantal;i++)
  70.                {if (namen[i] == noten)
  71.                {return(ritme[i]);}
  72.                 else {return(0)}
  73.                }
  74.               }
  75. }


And these are my errors:

Expand|Select|Wrap|Line Numbers
  1. In function 'void loop()':
  2.  
  3. 29:12: error: assignment of function 'void delay(long unsigned int)'
  4.  
  5.    {delay = lengte;}
  6.  
  7.             ^~~~~~
  8.  
  9. 29:12: error: cannot convert 'int' to 'void(long unsigned int)' in assignment
  10.  
  11. 31:32: error: 'tonen' cannot be used as a function
  12.  
  13.       tone(piezo, tonen(noten[i]), lengte);
  14.  
  15.                                 ^
  16.  
  17. 32:26: error: 'tonen' cannot be used as a function
  18.  
  19.         if((tonen(noten[i]) = 392) || (tonen(noten[i]) = 440))
  20.  
  21.                           ^
  22.  
  23. 32:53: error: 'tonen' cannot be used as a function
  24.  
  25.         if((tonen(noten[i]) = 392) || (tonen(noten[i]) = 440))
  26.  
  27.                                                      ^
  28.  
  29. 35:30: error: 'tonen' cannot be used as a function
  30.  
  31.       else if ((tonen(noten[i]) = 349) || (tonen(noten[i]) = 493))
  32.  
  33.                               ^
  34.  
  35. 35:57: error: 'tonen' cannot be used as a function
  36.  
  37.       else if ((tonen(noten[i]) = 349) || (tonen(noten[i]) = 493))
  38.  
  39.                                                          ^
  40.  
  41. 38:38: error: 'tonen' cannot be used as a function
  42.  
  43.                else if (tonen(noten[i]) = 330)
  44.  
  45.                                       ^
  46.  
  47. 41:39: error: 'tonen' cannot be used as a function
  48.  
  49.                else if ((tonen(noten[i]) = 294) || (tonen(noten[i]) = 440) || (tonen(noten[i]) = 493))
  50.  
  51.                                        ^
  52. 41:66: error: 'tonen' cannot be used as a function
  53.  
  54.                else if ((tonen(noten[i]) = 294) || (tonen(noten[i]) = 440) || (tonen(noten[i]) = 493))
  55.  
  56.                                                                   ^
  57. 41:93: error: 'tonen' cannot be used as a function
  58.  
  59.                else if ((tonen(noten[i]) = 294) || (tonen(noten[i]) = 440) || (tonen(noten[i]) = 493))
  60.  
  61.                                                                                              ^
  62.  
  63. 44:29: error: 'tonen' cannot be used as a function
  64.  
  65.       else if (tonen(noten[i]) = 262)
  66.  
  67.                              ^
  68. 66:15: error: a function-definition is not allowed here before '{' token
  69.  
  70.                {int i;
  71.  
  72.                ^
  73.  
  74. 74:1: error: expected '}' at end of input
  75.  
  76.  }
  77.  
  78.  ^
  79.  
  80. exit status 1
  81. assignment of function 'void delay(long unsigned int)'

Please help me. I would really appreciate it
4 Weeks Ago #1
Share this Question
Share on Google+
1 Reply


dev7060
Expert 100+
P: 183
29:12: error: assignment of function 'void delay(long unsigned int)'
Assigning something to a function?

29:12: error: cannot convert 'int' to 'void(long unsigned int)' in assignment
Comparison operator needs to be used instead of the assignment operator.

error: 'tonen' cannot be used as a function
"tonen" is an array.

66:15: error: a function-definition is not allowed here before '{' token
74:1: error: expected '}' at end of input
Watch out for the curly braces.
4 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.