// https://wokwi.com/projects/363250216927001601
// https://forum.arduino.cc/t/stepper-limit-switch-confusion/1120713
# include <ezButton.h>
# include "jButton.h"
# define HEART 6
# define EZLAMP 5
# define JLAMP 4
ezButton button(7); // create ezButton object that attach to pin 7;
jButton myButton; // simple button object
void setup() {
Serial.begin(115200);
Serial.println("jButton Whirled!\n");
button.setDebounceTime(20); // change this, fix it to be the same in jButton. Sorry, Mom!
myButton.setDebounceTime(20);
myButton.begin(7); // ok for everyone to watch the same pin
pinMode(HEART, OUTPUT);
pinMode(EZLAMP, OUTPUT);
pinMode(JLAMP, OUTPUT);
}
void loop() {
static unsigned long lastTime;
unsigned long now = millis();
/* can ezButton tolerate slow sservice? 2x debounce or lockout time here
if (now - lastTime < 400) return;
lastTime = now;
*/
digitalWrite(6, digitalRead(6) == LOW ? HIGH : LOW); // heartbeat
/* ezButton
button.loop();
if (button.isPressed()) {
Serial.println("The button is pressed");
digitalWrite(EZLAMP, HIGH);
}
if (button.isReleased()) {
Serial.println("The button is released");
digitalWrite(EZLAMP, LOW);
}
*/// jButton - should be exactly the same
static int testUOL = 20;
myButton.update(); // jButton service, like ezButton's loop
// myButton.update(); // jButton service, like ezButton's loop
// myButton.update(); // jButton service, like ezButton's loop
static int counter;
if (myButton.uolPress()) {
counter++;
Serial.print(counter);
Serial.println(" The jButton is pressed");
digitalWrite(JLAMP, HIGH);
}
if (myButton.uolRelease()) {
Serial.println(" The jButton is released");
digitalWrite(JLAMP, LOW);
}
}
void loopx() {
static unsigned long lastTime;
unsigned long now = millis();
// can ezButton tolerate slow sservice? 2x debounce or lockout time here
if (now - lastTime < 40) return;
lastTime = now;
//
digitalWrite(6, digitalRead(6) == LOW ? HIGH : LOW); // heartbeat
// ezButton
button.loop();
if (button.isPressed()) {
Serial.println("The button is pressed");
digitalWrite(EZLAMP, digitalRead(EZLAMP) == LOW ? HIGH : LOW);
}
if (button.isReleased())
Serial.println("The button is released");
// jButton - should be exactly the same
myButton.update(); // jButton service, like ezButton's loop
if (myButton.uolPress()) {
Serial.println(" The jButton is pressed");
digitalWrite(JLAMP, digitalRead(JLAMP) == LOW ? HIGH : LOW);
}
if (myButton.uolRelease())
Serial.println(" The jButton is released");
}
/*
return;
Serial.print("the button is ");
if (button[2].getState())
Serial.println("UP");
else
Serial.println("DOWN");
}
}
*/ezButton
jButton