#include <ezButton.h>
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
/// constants won't change
const int BUTTON_PIN = 7; // the number of the pushbutton pin
const int LED_PIN = 8; // the number of the LED pin
const int buzzer = 9; //buzzer to arduino pin 9
ezButton button(BUTTON_PIN); // create ezButton object that attach to pin 7;
// variables will change:
int ledState = LOW; // the current state of LED
int buzzerState = LOW;
void setup() {
pinMode(LED_PIN, OUTPUT); // set arduino pin to output mode
pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output
button.setDebounceTime(50); // set debounce time to 50 milliseconds
lcd.begin(16, 2);
lcd.clear();
}
void loop() {
button.loop(); // MUST call the loop() function first
lcd.setCursor(0, 0);
lcd.print("Led is ");
if(button.isPressed()) {
// toggle state of LED
ledState = !ledState;
buzzerState = !buzzerState;
// control LED arccoding to the toggleed sate
digitalWrite(LED_PIN, ledState);
tone(buzzerState, 500);
}
if (ledState == HIGH) {
lcd.print("ON ");
} else {
lcd.print("OFF");
}
}