#define LED 45 // D1(gpio5)
#define BUTTON1 48 //D2(gpio4)
#define BUTTON2 47 //D2(gpio4)
//Let's say you have your push button on pin 4
int sw1; // actual read value from pin4
int sw2;
int debounce = 20; //is the noise from switch
void setup() {
pinMode(BUTTON1, INPUT); // push button
pinMode(BUTTON2, INPUT); // push button
pinMode(LED, OUTPUT); // anything you want to control using a switch e.g. a Led
Serial.begin(115200);
}
void loop() {
sw1 = digitalRead(BUTTON1); // read the pushButton State
sw2 = digitalRead(BUTTON2); // read the pushButton State
delay(debounce);
if (sw1 == 0 && sw2 == 1) // catch change
{
blinkTen();
}
else if(sw1 == 1 && sw2 == 0){
on();
}
else{
off();
}
}
void blinkTen(){
for (int i = 0; i <= 9; i++) {
digitalWrite(LED, HIGH);
delay(300);
digitalWrite(LED, LOW);
delay(300);
Serial.print("i : ");
Serial.println(i);
}
}
void off(){
digitalWrite(LED, LOW);
}
void on(){
for (int i = 0; i <= 9; i++) {
digitalWrite(LED, HIGH);
delay(300);
}
}