/* jbutton nottubj */

# include "jbutton.h"  // check debounce time
# include <ezButton.h>

# include <Adafruit_NeoPixel.h>

ezButton ezA(A0);

jButton pA;

# define NINE       9
# define LED_PIN    8
# define LED_COUNT  NINE

Adafruit_NeoPixel disaply(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);


char shotCounter;
const unsigned long runTime = 3000L;
const byte runFactor = 3;

unsigned long now;    // always the time each loop
unsigned long aTimer;

bool running;

# define stabLED  10
# define STAB 333

void setup()
{
  mySetup(115200);
  xprintf("\nhello world.\n"); 

  pA.begin(A1);

  ezA.setDebounceTime(20);

  pinMode(10, OUTPUT);
  digitalWrite(stabLED, LOW);

  pinMode(11, OUTPUT);
  digitalWrite(11, LOW);

  disaply.begin();
  disaply.setPixelColor(1, 0xff00ff);
  disaply.show();
  delay(333);

  shotCounter = 9;
}

void loop()
{
  now = millis();

  pA.update();
  ezA.loop();

  bool ezAPressed = ezA.isPressed();
  bool pAPressed = pA.uolPress();


// blink per event
  static unsigned long stabStart;
  if (ezAPressed) {
    stabStart = now;
    digitalWrite(stabLED, HIGH);
  }
  if (now - stabStart >= STAB) digitalWrite(stabLED, LOW); 

// rule 0
  if (pAPressed || ezAPressed)
    shotCounter++;

// rule 1
  if (!running && shotCounter >= runFactor) {
      xprintf("turning on now\n");
      digitalWrite(11, HIGH);
      running = true;

      aTimer = now;
  }

// rule 2
  if (running && now - aTimer > runTime) {
    shotCounter -= runFactor; 
    if (shotCounter <= 0) {
      xprintf("turning off now\n");
      digitalWrite(11, LOW);
      shotCounter = 0;
      running = false;
    }
    else
      aTimer = now;
  }

//
  static int lastCount = -1;
  if (lastCount != shotCounter) {
    xprintf("and shotz = %d\n", shotCounter);
    lastCount = shotCounter;
  }

// separate redundat motor output section
  static bool motorControl;
  if (running && !motorControl) {
    Serial.println("Start the ");
    motorControl = true;
  }
  if (!running && motorControl) {
    Serial.println(" Stop the ");
    motorControl = false;
  }
}




// 

// programmer misses printf...

void xprintf(const char *format, ...)
{
  char buffer[256];
  va_list args;
  va_start(args, format);
  vsprintf(buffer, format, args);
  va_end(args);
  Serial.print(buffer);
}

// programmer forgets day of week, version

void mySetup(unsigned long bandRate)
{
  Serial.begin(bandRate);
   
  char s[] = __FILE__;
  byte b = sizeof(s);
  while ( (b > 0) && (s[b] != 47)) b--;
  char *u = s + b + 1;
 

  xprintf("%s  %s\n\n", __DATE__, u);

  xprintf("!\n");
}
AAA
LOGICAL .MOTOR
ezA