Hi people. I'm new around here, and also new about the introduction to arduino and C.
In this little "project" i'm asked to have a analog sensor which is the potentiometer, regulating the tone of a piezo buzzer using five switch cases according to the analog reading.
Here's what i came up with.
#define pi 6
#define pot A0
int cont = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.print("Move o potenciómetr");
}
void loop() {
// put your main code here, to run repeatedly:
int potValue = analogRead(pot);
switch(cont){
case 0:
if(potValue = 0){
tone(pi, 440,5);
delay(30);}
break;
case 1:
if(potValue > 0 || potValue <= 256){
tone(pi, 494,10);
delay(60);
}
break;
case 2:
if(potValue > 256 || potValue <= 512){
tone(pi,523,15);
delay(90);
}
break;
case 3:
if(potValue > 512 || potValue <= 768){
tone(pi,587, 20);
delay(120);
}
break;
case 4:
if(potValue > 768 || potValue <= 1023){
tone(pi, 622, 25);
delay(150);
}
}
}
The code compiles, but there's no tone at all. I don't know if it's the buzzer or the code, or both, but i'm only gonna test again tomorrow since someone took my other piezo and this one only heats up.
Glad for the help