Hi, I am trying to write code for a 'heat alarm' system just for fun. I am planning for two events to occur when the thermistor senses that the temperature rises above a certain point. I'm trying to get an LED to pulse from 0 to 255 and back to 0 with a delay of 10 milliseconds between each increment. I am also planning to make a piezo buzzer turn on for a second and then off for another at the same time. I tried doing this with multiple methods, but I realized that they ran one after another. So now I'm trying to do it with one while loop with an integer called switch. However, when I try to run it, I get some errors I don't understand.
Here's my code:
const int LED = 9;
const int Buzzer = 6;
int val = 0;
const int switch = 0;
void setup(){
pinMode(LED, OUTPUT);
pinMode(Buzzer, OUTPUT);
Serial.begin(9600);
}
void loop(){
val = analogRead(0);
Serial.println(val);
while(val > 540){
for(int x = 0; x < 255; x++){
analogWrite(LED, x);
delay(10);
if(x % 100 == 0){
if(switch == 0){
switch = 1;
}
else{
switch = 0;
}
}
if(switch == 1){
digitalWrite(Buzzer, HIGH);
}
else{
digitalWrite(Buzzer, LOW);
}
}
val = analogRead(0);
Serial.println(val);
}
}
The errors i'm getting:
sketch_jun14a:4: error: expected unqualified-id before 'switch'
sketch_jun14a.ino: In function 'void loop()':
sketch_jun14a:21: error: expected primary-expression before 'switch'
sketch_jun14a:21: error: expected )' before 'switch' sketch_jun14a:22: error: expected
(' before '=' token
sketch_jun14a:25: error: expected (' before '=' token sketch_jun14a:28: error: expected primary-expression before 'switch' sketch_jun14a:28: error: expected
)' before 'switch'
Thanks for all help in advance!