// 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.");
  }
}


uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
btn4:1.l
btn4:2.l
btn4:1.r
btn4:2.r
sw1:1
sw1:2
sw1:3
r1:1
r1:2
led1:A
led1:C
led2:A
led2:C
r2:1
r2:2
BLOCKING
LED
< <TOGGLE?
<BLOCK
led3:A
led3:C
led4:A
led4:C
led5:A
led5:C
prevS
lastS
lastF
led6:A
led6:C
led7:A
led7:C
led8:A
led8:C
PS is
LS is
LF is
led9:A
led9:C
D0D1D2D3D4D5D6D7GNDLOGIC
logic1:D0
logic1:D1
logic1:D2
logic1:D3
logic1:D4
logic1:D5
logic1:D6
logic1:D7
logic1:GND
CS is
sw2:1
sw2:2
sw2:3
<DSL