// ezButton doesn't suck, except when it does.
// working with a local copy of the library
# define BUSY 500
# define REST 1000
# define BLIP 100
# define DEBOUNCE 20
# define DSL
byte kBlips[] = { 4, A2, A1, A0, A3, A4, A5, 12}; // output pin
enum laTags {l0 = 0, l1, l2, l3, l4, l5, l6, l7}; // logic channel
void up(byte track)
{
digitalWrite(kBlips[track], HIGH);
}
void down(byte track)
{
digitalWrite(kBlips[track], LOW);
}
const byte nBlips = sizeof kBlips / sizeof *kBlips;
# include "ezButton.h"
// easyButton was an ezButton child with a new loop method ELSEWHERE I do hope.
const byte selectDelay = 7;
const byte selectLoop = 9;
const byte theLED = 6;
const byte busyLED = 8;
ezButton button(3);
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println(" Hello ezButton does it suck World!\n");
button.setDebounceTime(DEBOUNCE); // was 333 set debounce time to 50 milliseconds PLENTY.
pinMode(theLED, OUTPUT);
pinMode(busyLED, OUTPUT);
pinMode(selectDelay, INPUT_PULLUP); // closed switch == LOW, no delay
pinMode(selectLoop, INPUT_PULLUP); // closed switch == LOW, alto777 loop
for (byte ii = 0; ii < nBlips; ii++)
pinMode(kBlips[ii], OUTPUT);
}
static int counter;
void loop() {
static unsigned long lastTime;
unsigned long now = millis();
if (digitalRead(selectLoop) == HIGH)
button.dsLoop();
else
button.loop();
if (button.isPressed()) { // toggle the LED
digitalWrite(theLED, digitalRead(theLED) == LOW ? HIGH : LOW);
Serial.println("button is pressed");
busyWork();
}
if (button.isReleased()) Serial.println(" is released");
}
void busyWork()
{
Serial.print(counter); counter++;
if (digitalRead(selectDelay) == LOW) {
Serial.println(" I saw that.");
}
else {
Serial.print(" I saw that. Sleeping for a bit...");
digitalWrite(busyLED, HIGH);
delay(BUSY);
digitalWrite(busyLED, LOW);
delay(REST);
digitalWrite(busyLED, HIGH);
delay(BLIP);
digitalWrite(busyLED, LOW);
Serial.println(" and back on the job.");
}
}
BLOCKING
LED
< <TOGGLE?
<BLOCK
prevS
lastS
lastF
PS is
LS is
LF is
CS is
<DSL