hi guys, back on this again, i gave up on the pot with tap, it was a bit too glitchy...
so i am back to 1 blink led, and 1 fade led setup..
tap is working all fine as it should. i was just wondering how to have ''unlimited time'' between taps.
so i can go ultra uber slow fade (for a filter sweep using lfo led) ....or is there a limit to this?.
heres where i am as a reference.
/*
Tap Tempo using Jleds
*/
#include <jled.h>
int period = 2000;
JLed leds[] = {
JLed(3).Breathe(period).Forever(),
JLed(4).Blink(period/4*3, period/4).Forever(),
JLed(LED_BUILTIN).Blink(period/2, period/2).Forever()};
void setup()
{
pinMode( 12, INPUT ); /* tap button - press it to set the tempo */
}
int lastTapState = LOW; /* the last tap button state */
unsigned long currentTimer[2] = { 500, 500 }; /* array of most recent tap counts */
void loop()
{
/* read the button on pin 12, and only pay attention to the
HIGH-LOW transition so that we only register when the
button is first pressed down */
int tapState = digitalRead( 12 );
if( tapState == LOW && tapState != lastTapState )
{
tap(); /* we got a HIGH-LOW transition, call our tap() function */
}
lastTapState = tapState; /* keep track of the state */
// update leds
for (auto& led : leds) {led.Update();}
delay(1);
}
unsigned long lastTap = 0; /* when the last tap happened */
void tap()
{
/* we keep two of these around to average together later */
currentTimer[1] = currentTimer[0];
currentTimer[0] = millis() - lastTap;
lastTap = millis();
// establish new period
period = ((currentTimer[0] + currentTimer[1])/2);
// update leds period
leds[0] = JLed(3).Breathe(period).Forever();
leds[1] = JLed(4).Blink(period/4*3, period/4).Forever();
leds[4] = JLed(LED_BUILTIN).Blink(period/2, period/2).Forever();
}