Having trouble implementing debounce into my code

I am having trouble implementing debounce into my code, the aim of which is to have five buttons, A to E, and each button has a corresponding LED, LED A, LED B, LED C etc.

I want the code to work so when I press a button it will turn on its LED and the LED will stay on, if I then press a different button, it will turn off the previously on LED and its own LED on.

If a button is pressed twice, it will turn off all LEDs.

After a lot of reading and YouTube I have achieved this with the below code, but now I have connected a breadboard to test it I am getting issues with debouncing. The code works but the switching is intermittent.

It seem to me that each example of debouncing code I have tried conflicts with my existing code and due to my limited knowledge of Arduino I am struggling to find a solution that keeps my original code working.

Is there an obvious way of doing it that I am missing?

int buttonPin1 = 1;
int buttonPin2 = 2;
int buttonPin3 = 3;
int buttonPin4 = 4;
int buttonPin5 = 5;

int ledPin1 = 6;
int ledPin2 = 7;
int ledPin3 = 8;
int ledPin4 = 9;
int ledPin5 = 10;

int ledState1 = LOW;
int ledState2 = LOW;
int ledState3 = LOW;
int ledState4 = LOW;
int ledState5 = LOW;

int buttonState1;
int lastButtonState1 = LOW;
int buttonState2;
int lastButtonState2 = LOW;
int buttonState3;
int lastButtonState3 = LOW;
int buttonState4;
int lastButtonState4 = LOW;
int buttonState5;
int lastButtonState5 = LOW;

int dt = 50;

void setup() {
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
  pinMode(buttonPin5, INPUT);

  digitalWrite(ledPin1, HIGH);            //turn LED1 off
  digitalWrite(ledPin2, HIGH);            //turn LED2 off
  digitalWrite(ledPin3, HIGH);            //turn LED3 off
  digitalWrite(ledPin4, HIGH);            //turn LED4 off
  digitalWrite(ledPin5, HIGH);           //turn LED5 off
  ledState1 = HIGH;                      //set LED1 state to off
  ledState2 = HIGH;                      //set LED2 state to off
  ledState3 = HIGH;                      //set LED3 state to off
  ledState4 = HIGH;                      //set LED4 state to off
  ledState5 = HIGH;                      //set LED5 state to off

  dt;
}

void loop() {

  ///BUTTON 1///

  buttonState1 = digitalRead(buttonPin1);            //get new button1 state
  if (lastButtonState1 == HIGH && buttonState1 == LOW) {     //if the button1 is pressed
    if (ledState1 == HIGH) {                 //if LED1 is off
      digitalWrite(ledPin1, LOW);           //turn LED1 on
      digitalWrite(ledPin2, HIGH);            //turn LED2 off
      digitalWrite(ledPin3, HIGH);            //turn LED3 off
      digitalWrite(ledPin4, HIGH);            //turn LED4 off
      digitalWrite(ledPin5, HIGH);            //turn LED5 off
      ledState1 = LOW;                      //set LED1 state to on
      ledState2 = HIGH;                      //set LED2 state to off
      ledState3 = HIGH;                      //set LED3 state to off
      ledState4 = HIGH;                      //set LED4 state to off
      ledState5 = HIGH;                      //set LED5 state to off
    }
    else {                                //or
      digitalWrite(ledPin1, HIGH);            //turn LED1 off
      ledState1 = HIGH;                      //change LED1 state to off
    }
  }
  lastButtonState1 = buttonState1;                      //set old button1 state

  ///BUTTON 2///

  buttonState2 = digitalRead(buttonPin2);            //get new button2 state
  if (lastButtonState2 == HIGH && buttonState2 == LOW) {     //if the button2 is pressed
    if (ledState2 == HIGH) {                 //if LED2 is off
      digitalWrite(ledPin1, HIGH);            //turn LED1 off
      digitalWrite(ledPin2, LOW);           //turn LED2 on
      digitalWrite(ledPin3, HIGH);            //turn LED3 off
      digitalWrite(ledPin4, HIGH);            //turn LED4 off
      digitalWrite(ledPin5, HIGH);            //turn LED5 off
      ledState1 = HIGH;                      //set LED1 state to off
      ledState2 = LOW;                      //set LED2 state to on
      ledState3 = HIGH;                      //set LED3 state to off
      ledState4 = HIGH;                      //set LED4 state to off
      ledState5 = HIGH;                      //set LED5 state to off
    }
    else {                                //or
      digitalWrite(ledPin2, HIGH);            //turn LED2 off
      ledState2 = HIGH;                      //change LED2 state to off
    }
  }
  lastButtonState2 = buttonState2;                      //set old button2 state

  ///BUTTON 3///

  buttonState3 = digitalRead(buttonPin3);            //get new button3 state
  if (lastButtonState3 == HIGH && buttonState3 == LOW) {     //if the button3 is pressed
    if (ledState3 == HIGH) {                 //if LED3 is off
      digitalWrite(ledPin1, HIGH);            //turn LED1 off
      digitalWrite(ledPin2, HIGH);            //turn LED2 off
      digitalWrite(ledPin3, LOW);           //turn LED3 on
      digitalWrite(ledPin4, HIGH);            //turn LED4 off
      digitalWrite(ledPin5, HIGH);            //turn LED5 off
      ledState1 = HIGH;                      //set LED1 state to off
      ledState2 = HIGH;                      //set LED2 state to off
      ledState3 = LOW;                      //set LED3 state to on
      ledState4 = HIGH;                      //set LED4 state to off
      ledState5 = HIGH;                      //set LED5 state to off
    }
    else {                                //or
      digitalWrite(ledPin3, HIGH);            //turn LED3 off
      ledState3 = HIGH;                      //change LED3 state to off
    }
  }
  lastButtonState3 = buttonState3;                      //set old button3 state

  ///BUTTON 4///

  buttonState4 = digitalRead(buttonPin4);            //get new button4 state
  if (lastButtonState4 == HIGH && buttonState4 == LOW) {     //if the button4 is pressed
    if (ledState4 == HIGH) {                 //if LED4 is off
      digitalWrite(ledPin1, HIGH);            //turn LED1 off
      digitalWrite(ledPin2, HIGH);            //turn LED2 off
      digitalWrite(ledPin3, HIGH);            //turn LED3 off
      digitalWrite(ledPin4, LOW);           //turn LED4 on
      digitalWrite(ledPin5, HIGH);            //turn LED5 off
      ledState1 = HIGH;                      //set LED1 state to off
      ledState2 = HIGH;                      //set LED2 state to off
      ledState3 = HIGH;                      //set LED3 state to off
      ledState4 = LOW;                      //set LED4 state to on
      ledState5 = HIGH;                      //set LED5 state to off
    }
    else {                                //or
      digitalWrite(ledPin4, HIGH);            //turn LED4 off
      ledState4 = HIGH;                      //change LED4 state to off
    }
  }
  lastButtonState4 = buttonState4;                      //set old button4 state

  ///BUTTON 5///

  buttonState5 = digitalRead(buttonPin5);            //get new button5 state
  if (lastButtonState5 == HIGH && buttonState5 == LOW) {     //if the button5 is pressed
    if (ledState5 == HIGH) {                 //if LED5 is off
      digitalWrite(ledPin1, HIGH);            //turn LED1 off
      digitalWrite(ledPin2, HIGH);            //turn LED2 off
      digitalWrite(ledPin3, HIGH);            //turn LED3 off
      digitalWrite(ledPin4, HIGH);            //turn LED4 off
      digitalWrite(ledPin5, LOW);           //turn LED5 on
      ledState1 = HIGH;                      //set LED1 state to off
      ledState2 = HIGH;                      //set LED2 state to off
      ledState3 = HIGH;                      //set LED3 state to off
      ledState4 = HIGH;                      //set LED4 state to off
      ledState5 = LOW;                      //set LED5 state to on
    }
    else {                                //or
      digitalWrite(ledPin5, HIGH);            //turn LED5 off
      ledState5 = HIGH;                      //change LED5 state to off
    }
  }
  lastButtonState5 = buttonState5;                      //set old button5 state

  dt;                                     //delay


}

Have you seen Nick Gammons tutorial on switches? It contains good info and examples for debouncing.

Gammon Forum : Electronics : Microprocessors : Switches tutorial

Try with two buttons and two LEDs first and then add more buttons and LEDs in an incremental way. Here is an example, which uses Debounce.h Library to attribute bouncing time to a closed button.

1. Interfacing circuit with two Buttons and two LEDs (Fig-1)
sw2led2
Figure-1:

The Library assumes that the switch is wired with pull-up resistor which could be external or internal. The library provides a debounce time of 50 ms. Switch debounce refers to the process of waiting until bounces of the switch are decayed and the switch has settled to the closed condition. The Library also contains count() method to account for the number of times a button has been pressed over a time boundary.

The library has a method named read() which returns HIGH if the switch is closed or LOW if the switch is open.

2. Test Sketch

#include<Debounce.h>
#define button1 8
#define LED1 6
Debounce Button(button1);

void setup()
{
  Serial.begin(9600);
  pinMode(8, INPUT_PULLUP);
  pinMode(LED1, OUTPUT);
  //---Test Codes----------
  while (1)
  {
    byte statusB1 = Button.read(); //statusB1 is updated once Button1 is de-bounced

    if (statusB1 == HIGH)			//Buton1 is closed 
    {
      Serial.println(statusB1); 		//shows: 1 (= HIGH)
      digitalWrite(LED1, statusB1);  	//LED1 turns ON
      break;  						//go out of the while(1) loop.
    }
  }
}

void loop()
{

}

3. Extend the concept of Step-2 to include Button-2 and L of Fig-1.
4. You may find worth reading the attached file.
Ch-4DIOLec.pdf (657.1 KB)

const int buttons = 5;
const int buttonPin[buttons] = {1, 2, 3, 4, 5};

const int ledPin[buttons] = {6, 7, 8, 9, 10};

int ledState[buttons] = {LOW, LOW, LOW, LOW, LOW};

int buttonState[buttons];
int lastButtonState[buttons] = {LOW, LOW, LOW, LOW, LOW};

int dt = 50;

void setup() {
  for (int b=0; b<buttons; b++) {
    pinMode(ledPin[b], OUTPUT);
    pinMode(buttonPin[b], INPUT);

    digitalWrite(ledPin[b], HIGH);            //turn LED off
    ledState[b] = HIGH;                      //set LED state to off
  }
  delay(dt);
}

void loop() {
  for (int b=0; b<buttons; b++) {
    buttonState[b] = digitalRead(buttonPin[b]);            //get new button state
    if (lastButtonState[b] == HIGH && buttonState[b] == LOW) {     //if the button is pressed
      if (ledState[b] == HIGH) {                 //if LED is off
        digitalWrite(ledPin[b], LOW);           //turn LED on
        ledState[b] = LOW;                      //set LED state to on
        for (int b2=0; b2<buttons; b2++) {
          if (b2 != b) {
            digitalWrite(ledPin[b2], HIGH);            //turn other LED off
            ledState[b2] = HIGH;                      //set other LED state to off
          }
        }
      }
    else {                                //or
      digitalWrite(ledPin[b], HIGH);            //turn LED off
      ledState[b] = HIGH;                      //change LED state to off
      }
    }
    lastButtonState[b] = buttonState[b];                      //set old button state
  }

  delay(dt);                                     //delay

}

Note: you should not be using pin 1 on many types of Arduino.

The technique that I usually use is to have a last known state variable and a counter for each switch.
Each time through the loop, the switch is read, and that value is compared with the last known state. If they match, the counter is set to zero. If they don't match, the counter is incremented. Then, the counter value is checked. If it has reached a threshold value( I find 10 works most times ) then the last known value is set to match the switch, and the counter is reset to zero.
When making a decision based on the switch, the last known state is checked, not the switch itself.

Doesn't.

   delay(dt);

does, and may be all you need to crudely simply debounce or ride past switch glitches.

But. How are your switches wired? Are you using an external pull down resistor? You may just be getting spurious switch signals if not.

Better for reasons:

Use INPUT_PULLUP for the pin mode, and check digitalRead() returning LOW when pressed.

Many ppl use

# define PRESST HIGH

and check digitalRead() returning PRESST.

That makes changing all the switches' "sense" to be opposite a matter of a one line change.

# define PRESST LOW  // changed to pulled up pins switched to ground

HTH

a7

You could use a hardware solution with better switches or with external capacitors.

Or software-wise, Nick Gammon's code from Gammon Forum : Electronics : Microprocessors : Switches tutorial enforces a minimum time between transitions, so it can switch on the leading edge of the noise and ignore the following trash:

```
const byte switchPin = 8;
byte oldSwitchState = HIGH;  // assume switch open because of pull-up resistor
const unsigned long debounceTime = 10;  // milliseconds
unsigned long switchPressTime;  // when the switch last changed state

void setup ()
  {
  Serial.begin (115200);
  pinMode (switchPin, INPUT_PULLUP);
  }  // end of setup

void loop ()
  {
  // see if switch is open or closed
  byte switchState = digitalRead (switchPin);
  
  // has it changed since last time?
  if (switchState != oldSwitchState)
    {
    // debounce
    if (millis () - switchPressTime >= debounceTime)
       {
       switchPressTime = millis ();  // when we closed the switch 
       oldSwitchState =  switchState;  // remember for next time 
       if (switchState == LOW)
          {
          Serial.println ("Switch closed.");
          }  // end if switchState is LOW
       else
          {
          Serial.println ("Switch opened.");
          }  // end if switchState is HIGH
           
       }  // end if debounce time up
        
    }  // end of state change
     
  // other code here ...
   
  }  // end of loop
```

It's responsive and non-blocking.

LIke this?

-jim lee

Hello jimLee

Could you publish the sketch, please.

@remmy
there is a "Debounce" example in the Arduino IDE.

You can create a simple class based on that example and then you can reuse the code for 5 buttons.

/*
    debounce - one of five

    https://forum.arduino.cc/t/having-trouble-implementing-debounce-into-my-code/1119513/9

    2023-04-26 by noiasca
    sketch in forum
*/

// a simple button class
class Button {                                   // class to debounce switches
    const uint8_t buttonPin;                     // the pin for the button
    static constexpr byte debounceDelay = 20;    // the debounce time - one value for all buttons (hence "static")
    const bool active;                           // is the button HIGH or LOW active
    bool lastButtonState = HIGH;                 // previous state of pin
    byte lastDebounceTime = 0;                   // previous debounce time (we just need short debounce delay, so the rollover of the byte variable works fine and spares 3 bytes compared to an unsigned long)

  public:
    Button(uint8_t attachTo, bool active = LOW) : buttonPin(attachTo), active(active) {}

    void begin() {                               // sets the pinMode and optionally activates the internal pullups
      if (active == LOW)
        pinMode(buttonPin, INPUT_PULLUP);
      else
        pinMode(buttonPin, INPUT);
    }

    bool wasPressed() {
      bool buttonState = LOW;
      byte reading = LOW;
      if (digitalRead(buttonPin) == active) reading = HIGH;
      if (((millis() & 0xFF ) - lastDebounceTime) > debounceDelay) {
        if (reading != lastButtonState && lastButtonState == LOW) {
          buttonState = HIGH;
        }
        lastDebounceTime = millis() & 0xFF;   // we store just the last byte from millis()
        lastButtonState = reading;
      }
      return buttonState;
    }
};

Button button[] {2, 3, 4, 5, 6};               // create button object on these pins, by default, activate internal pullups
const uint8_t outputPin[] {7, 8, 9, 10, 11};   // pins for outputs
const size_t noOfPins = sizeof(outputPin);     // calculate how many pins are used
int currentLed = -1;                           // active LED, -1 if none

void setup() {
  for (int i = 0; i < noOfPins; i++) {         // for each button/pin ...
    button[i].begin();                         // call begin 
    pinMode(outputPin[i], OUTPUT);             // set LED pins to output
  }
}

void loop() {
  for (int i = 0; i < noOfPins; i++) {    
    if (button[i].wasPressed()) {         
      if (currentLed == i) {
        digitalWrite(outputPin[currentLed], LOW);  // switch off LED
        currentLed = -1;                           // mark as no active LED
      }
      else {
        digitalWrite(outputPin[currentLed], LOW);  // switch off old LED
         currentLed = i;                           // remember new LED
        digitalWrite(outputPin[currentLed], HIGH); // switch on new LED
      }
    }
  }
}

to play around:

In general - Arrays are your friends.
Don't duplicate code in your sketch. Write code once - use it multiple times.

Thank you @noiasca (your code works great) and to everyone else who took the time to respond, as you can tell from my version I am pretty green when it comes to coding and seeing everyone’s take on it has given me a lot to look into and get my head around.

I was not aware of arrays (bit of an eye opener with how efficient the code is) so that is certainly what I am next concentrating on, I will study the Nick Gammon guide too, that looks very useful.

Thanks again, really appreciate it

looks this over

// check multiple buttons and toggle LEDs

enum { Off = HIGH, On = LOW };

byte pinsLed [] = { 10, 11, 12 };
byte pinsBut [] = { A1, A2, A3 };
#define N_BUT   sizeof(pinsBut)

byte butState [N_BUT];

// -----------------------------------------------------------------------------
int
chkButtons ()
{
    for (unsigned n = 0; n < sizeof(pinsBut); n++)  {
        byte but = digitalRead (pinsBut [n]);

        if (butState [n] != but)  {
            butState [n] = but;

            delay (10);     // debounce

            if (On == but)
                return n;
        }
    }
    return -1;
}

// -----------------------------------------------------------------------------
void
loop ()
{
    switch (chkButtons ())  {
    case 2:
        digitalWrite (pinsLed [2], ! digitalRead (pinsLed [2]));
        break;

    case 1:
        digitalWrite (pinsLed [1], ! digitalRead (pinsLed [1]));
        break;

    case 0:
        digitalWrite (pinsLed [0], ! digitalRead (pinsLed [0]));
        break;
    }
}

// -----------------------------------------------------------------------------
void
setup ()
{
    Serial.begin (9600);

    for (unsigned n = 0; n < sizeof(pinsBut); n++)  {
        pinMode (pinsBut [n], INPUT_PULLUP);
        butState [n] = digitalRead (pinsBut [n]);
    }

    for (unsigned n = 0; n < sizeof(pinsLed); n++)  {
        digitalWrite (pinsLed [n], Off);
        pinMode      (pinsLed [n], OUTPUT);
    }
}

Consider

#define ProjectName "Having trouble implementing debounce into my code"
/* BLOCK COMMENT
 https://forum.arduino.cc/t/having-trouble-implementing-debounce-into-my-code/1119513
 https://europe1.discourse-cdn.com/arduino/original/4X/7/e/0/7e0ee1e51f1df32e30893550c85f0dd33244fb0e.jpeg
*/
// make names
enum TimerCtrl {Off, On, Blink};
enum TimerRun {NotTriggered, Triggered};
enum TimerState {Stopped, Running};
enum ButtonAction {Idle, BecomesPressed};
enum LedStates {UnLit, Lit};
// make variables
constexpr uint8_t ButtonPins[] {A0};
constexpr uint8_t LedPins[] {9};
// make structures
struct TIMERctrl
{
 uint32_t intervalMillis;
 uint32_t previousMillis;
 uint8_t timerCtrl;
 void start(uint32_t intervalMillis_, uint8_t timerCtrl_, uint32_t currentMillis_)
 {
   previousMillis = currentMillis_;
   intervalMillis = intervalMillis_;
   timerCtrl = timerCtrl_;
 }
 void stop()
 {
   timerCtrl = Off;
 }
 uint8_t run(uint32_t currentMillis)
 {
   if ((currentMillis - previousMillis >= intervalMillis && timerCtrl) == NotTriggered) return NotTriggered;
   timerCtrl == Blink ? previousMillis = currentMillis : timerCtrl = Off;
   return Triggered;
 }
 uint8_t isRunning()
 {
   return timerCtrl == Off ? Stopped : Running;
 }
};
struct TIMERpure
{
 uint32_t intervalMillis;
 uint32_t previousMillis;
};
struct KNOP2LED
{
 uint8_t knop;
 uint8_t led;
 uint8_t stateOld;
 TIMERctrl clickMe;
 TIMERpure debounce;
 void make(uint8_t knop_, uint8_t led_)
 {
   knop = knop_;
   led = led_;
   pinMode(knop, INPUT_PULLUP);
   pinMode(led, OUTPUT);
   digitalWrite(led, Lit);
   delay(1000);
   digitalWrite(led, UnLit);
   delay(1000);
   debounce.intervalMillis = 20;
 }
 uint8_t buttonAction(uint32_t currentMillis)
 {
   uint8_t returnMe = Idle;
   if ( currentMillis - debounce.previousMillis >= debounce.intervalMillis)
   {
     debounce.previousMillis = currentMillis;
     uint8_t stateNew = digitalRead(knop) ? LOW : HIGH;
     if (stateOld != stateNew)
     {
       stateOld = stateNew;
       if (stateNew == HIGH) returnMe = BecomesPressed;
     }
   }
   return returnMe;
 }
};
KNOP2LED knop2leds[sizeof(ButtonPins)];
// tools
void heartBeat(int LedPin, uint32_t currentMillis)
{
 static bool setUp = false;
 if (!setUp) pinMode (LedPin, OUTPUT), setUp = !setUp;
 digitalWrite(LedPin, (currentMillis / 500) % 2);
}
void setup()
{
 Serial.begin(115200);
 Serial.println(ProjectName);
 Serial.println(__FILE__);
 Serial.println(__DATE__);
 Serial.println(__TIME__);
 uint8_t index = 0;
 for (auto &knop2led : knop2leds)
 {
   knop2led.make(ButtonPins[index], LedPins[index]);
   index++;
 }
}
void loop()
{
 uint32_t currentMillis = millis();
 heartBeat(LED_BUILTIN, currentMillis);
 for (auto &knop2led : knop2leds)
 {
   if (knop2led.buttonAction(currentMillis) == BecomesPressed)
   {
     if (knop2led.clickMe.isRunning() == Stopped)
     {
       knop2led.clickMe.start(1000, On, currentMillis);
     }
     else
     {
       knop2led.clickMe.stop();
       for (auto &knop2led : knop2leds) digitalWrite(knop2led.led, UnLit);
     }
   }
   if (knop2led.clickMe.run(currentMillis) == Triggered)
   {
     digitalWrite(knop2led.led, Lit);
   }
 }
}
//------------------------------------------------------------

Have a nice day and enjoy coding in C++.

You mean like this?

#include <mechButton.h>

mechButton  btn1(2);
mechButton  btn2(3);
mechButton  btn3(4);
mechButton  btn4(5);
mechButton  btn5(6);
int         LEDOnNow;

void setup() {
  
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  allLEDOff();
  btn1.setCallback(btn1Click);
  btn2.setCallback(btn2Click);
  btn3.setCallback(btn3Click);
  btn4.setCallback(btn4Click);
  btn5.setCallback(btn5Click);
}


void allLEDOff(void) {

  digitalWrite(7,LOW);
  digitalWrite(8,LOW);
  digitalWrite(9,LOW);
  digitalWrite(10,LOW);
  digitalWrite(11,LOW);
  LEDOnNow = 0;
}


void btn1Click(void) {

  if (!btn1.trueFalse()) {
    if (LEDOnNow!=1) {
      allLEDOff();
      digitalWrite(7,HIGH);
      LEDOnNow = 1;
    } else {
      allLEDOff();
    }
  }
}


void btn2Click(void) {

  if (!btn2.trueFalse()) {
    if (LEDOnNow!=2) {
      allLEDOff();
      digitalWrite(8,HIGH);
      LEDOnNow = 2;
    } else {
      allLEDOff();
    }
  }
}


void btn3Click(void) {

  if (!btn3.trueFalse()) {
    if (LEDOnNow!=3) {
      allLEDOff();
      digitalWrite(9,HIGH);
      LEDOnNow = 3;
    } else {
      allLEDOff();
    }
  }
}


void btn4Click(void) {

  if (!btn4.trueFalse()) {
    if (LEDOnNow!=4) {
      allLEDOff();
      digitalWrite(10,HIGH);
      LEDOnNow = 4;
    } else {
      allLEDOff();
    }
  }
}

void btn5Click(void) {

  if (!btn5.trueFalse()) {
    if (LEDOnNow!=5) {
      allLEDOff();
      digitalWrite(11,HIGH);
      LEDOnNow = 5;
    } else {
      allLEDOff();
    }
  }
}


void loop() { idle(); }

Why do you want the code published? It's right there in the simulation.

-jim lee

Hello

I can´t use it one my mobil.

Ah! got it.

-jim