0

I'm new in this arduino world, and I'm having some trouble. I am programming something for a school assignment. The program gives an error, and my teacher also doesn't know how to solve it. Maybe someone can help me?

#include <CapacitiveSensor.h>
#define speaker 

CapacitiveSensor   cs_2_3 = CapacitiveSensor(2,3);        
CapacitiveSensor   cs_2_4 = CapacitiveSensor(2,4);         
CapacitiveSensor   cs_2_5 = CapacitiveSensor(2,5);     
CapacitiveSensor   cs_2_6 = CapacitiveSensor(2,6);     
CapacitiveSensor   cs_2_7 = CapacitiveSensor(2,7);      
CapacitiveSensor   cs_2_8 = CapacitiveSensor(2,8);         
CapacitiveSensor   cs_2_9 = CapacitiveSensor(2,9);  
CapacitiveSensor   cs_2_10 = CapacitiveSensor(2,10);     

int s1;
int s2;
int s3;
int s4;
int s5;
int s6;
int s7;
int s8;


void setup(){ 
  Serial.begin(9600);
}

void loop()                    
{

  s1 =  cs_2_3.capacitiveSensor(3000);
  s2 =  cs_2_4.capacitiveSensor(3000);
  s3 =  cs_2_5.capacitiveSensor(3000);
  s4 =  cs_2_6.capacitiveSensor(3000);
  s5 =  cs_2_7.capacitiveSensor(3000);
  s6 =  cs_2_8.capacitiveSensor(3000);
  s7 =  cs_2_9.capacitiveSensor(3000);
  s8 =  cs_2_10.capacitiveSensor(3000);

  Serial.print("s1: ");
  Serial.println(s1);
  Serial.print("s2: ");
  Serial.println(s2);
  Serial.print("s3: ");
  Serial.println(s3);
  Serial.print("s4: ");
  Serial.println(s4);
  Serial.print("s5: ");
  Serial.println(s5);
  Serial.print("s6: ");
  Serial.println(s6);
  Serial.print("s7: ");
  Serial.println(s7);
  Serial.print("s8: ");
  Serial.println(s8);


  if (s1 > 500){  
    tone(speaker,131);   
   }
  else if (s2 > 500){ 
    tone(speaker,147);   
   }
  else if (s3 > 500){ 
    tone(speaker,165);
   }
  else if (s4 > 500){ 
    tone(speaker,175);
   }
  else if (s5 > 500){ 
    tone(speaker,196);
   }
  else if (s6 > 500){ 
    tone(speaker,220);
   }
  else if (s7 > 500){ 
    tone(speaker,247);
   }
  else if (s8 > 500){ 
    tone(speaker,262);  
   }

  if (s1<=500  &&  s2<=500  &&  s3<=500 && s4<=500  &&  s5<=500  &&  s6<=500 &&  s7<=500 &&  s8<=500){
    noTone(speaker);
  }
}
  • 1
    Tell the line where the error is given. – Michel Keijzers Nov 13 '18 at 11:59
  • This is unrelated to your question but the else if construct does not look very elegant, especially if tone s1 is supposed to have an equal priority to say s8. Can you find another way of doing this part of the code? – MichaelT Nov 13 '18 at 13:21
  • Hint: What does "tone(speaker,131); " become if "#define speaker"? – Mikael Patel Nov 13 '18 at 14:08
  • This is the line where the error is given: else if (s8 > 500){ tone(speaker,262); – Anouk Jansen Nov 20 '18 at 9:07
6

This:

#define speaker

defines "speaker" as nothing, an empty string. Then:

tone(speaker,131);

is translated into

tone(,131);

which makes no sense. The compiler expected to find an expression before the comma.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.