#define BTN_RED 25
#define BTN_GREEN 26
#define LED_PIN 2
// variables will change:
int led_state = LOW; // the current state of LED
int btn_red; // the current state of button
int btn_green = LOW;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.write("Giữ nút đỏ để dừng đèn led");
Serial.write("Giữ nút xanh để thay đổi tần suất sáng đèn led");
pinMode(LED_PIN, OUTPUT);
pinMode(BTN_RED, INPUT_PULLUP);
pinMode(BTN_GREEN, INPUT_PULLUP);
btn_red = digitalRead(BTN_RED);
}
void loop() {
btn_red = digitalRead(BTN_RED);
if(btn_red == HIGH){
btn_green = digitalRead(BTN_GREEN); // read new state
if (btn_green == HIGH) {
digitalWrite(LED_PIN, HIGH);
delay(3000);
digitalWrite(LED_PIN, LOW);
delay(1000);
}else{
digitalWrite(LED_PIN, HIGH);
delay(500);
digitalWrite(LED_PIN, LOW);
delay(500);
}
}
else{
digitalWrite(LED_PIN, LOW);
}
}