#include <ezButton.h>
ezButton button1(25); // create ezButton object that attach to pin 6;
ezButton button2(26); // create ezButton object that attach to pin 7;
ezButton button3(27); // create ezButton object that attach to pin 8;
ezButton button4(14); // create ezButton object that attach to pin 8;
void setup() {
Serial.begin(9600);
button1.setDebounceTime(50); // set debounce time to 50 milliseconds
button2.setDebounceTime(50); // set debounce time to 50 milliseconds
button3.setDebounceTime(50); // set debounce time to 50 milliseconds
button4.setDebounceTime(50); // set debounce time to 50 milliseconds
}
void loop() {
button1.loop(); // MUST call the loop() function first
button2.loop(); // MUST call the loop() function first
button3.loop(); // MUST call the loop() function first
button4.loop(); // MUST call the loop() function first
int btn1State = button1.getState();
int btn2State = button2.getState();
int btn3State = button3.getState();
int btn4State = button4.getState();
Serial.print("button 1 state: ");
Serial.println(btn1State);
Serial.print("button 2 state: ");
Serial.println(btn2State);
Serial.print("button 3 state: ");
Serial.println(btn3State);
Serial.print("button 4 state: ");
Serial.println(btn4State);
if(button1.isPressed()){
Serial.println("The button 1 is pressed");
digitalWrite(34, HIGH);
}
if(button1.isReleased()){
Serial.println("The button 1 is released");
digitalWrite(34, LOW);
}
if(button2.isPressed()){
Serial.println("The button 2 is pressed");
digitalWrite(35, HIGH);
}
if(button2.isReleased()){
Serial.println("The button 2 is released");
digitalWrite(35, LOW);
}
if(button3.isPressed()){
Serial.println("The button 3 is pressed");
digitalWrite(32, HIGH);
}
if(button3.isReleased()){
Serial.println("The button 3 is released");
digitalWrite(32, LOW);
}
if(button4.isPressed()){
Serial.println("The button 4 is pressed");
digitalWrite(33, HIGH);
}
if(button4.isReleased()){
Serial.println("The button 4 is released");
digitalWrite(33,LOW);
}
}
/*#define but1 25
#define but2 26
#define but3 27
#define but4 14
#define rel1 34
#define rel2 35
#define rel3 32
#define rel4 33
int out1;
int out2;
int out3;
int out4;
void setup()
{
pinMode(INPUT_PULLUP,but1);
pinMode(INPUT_PULLUP,but2);
pinMode(INPUT_PULLUP,but3);
pinMode(INPUT_PULLUP,but4);
pinMode(OUTPUT,rel1);
pinMode(OUTPUT,rel2);
pinMode(OUTPUT,rel3);
pinMode(OUTPUT,rel4);
}
void loop()
{
out1=digitalRead(but1);
out2=digitalRead(but2);
out3=digitalRead(but3);
out4=digitalRead(but4);
if(out1==LOW)
{
Serial.println(rel1);
digitalWrite(rel1, HIGH);
}
else if(out2==LOW)
{
Serial.println(rel2);
digitalWrite(rel2, HIGH);
}
else if(out3==LOW)
{
Serial.println(rel3);
digitalWrite(rel3, HIGH);
}
else if(out4==LOW)
{
Serial.println(rel4);
digitalWrite(rel4, HIGH);
}
else{
digitalWrite(rel1, LOW);
digitalWrite(rel2, LOW);
digitalWrite(rel3, LOW);
digitalWrite(rel4, LOW);
}
}*/