const int buttonPin = 12;
int oldValue = LOW;
void setup()
{
Serial.begin(115200);
Serial.println("Press the button.");
pinMode(buttonPin, INPUT);
pinMode(8, OUTPUT);
pinMode(4, OUTPUT);
}
void loop()
{
int newValue = digitalRead(buttonPin);
if(newValue != oldValue)
{
if(newValue == HIGH)
{
for(int i=0,i<100,i++)
}
{
Serial.println("The button is pressed.");
tone(8,260);
delay(700);
noTone(8);
delay(700);
digitalWrite(4, HIGH);
delay(700);
digitalWrite(4,LOW);
delay(100);
tone(8,520);
delay(700);
noTone(8);
digitalWrite(4, HIGH);
delay(700);
digitalWrite(4, LOW);
}
else
{
Serial.println("The button is released.");
}
oldValue = newValue;
}
delay(100);
}