Score counter for pinball machine

Greetings All!

So I've got a fun project that I'm making good progress on that I want to share and ask for advice. As a bit of introduction, I've never used or coded with Arduino but knew a bit of visual basic and wrote a few AutoCAD lisp routines some years back. I'm a lifelong tinkerer and always enjoy taking on various projects.

So, I have an old single player pinball machine (Home Run (Gottlieb 1972)) and the score reels max out at 99,990. With my friends and I typically scoring well over 300k it is sometimes hard to remember how many times the score has "rolled over". On the backglass just above the score reels is 9 evenly spaced flags so I thought it would be cool to have a light turn on behind a flag whenever the score rolled over. Well, I just happen to have a bunch of pre-wired LED's and an Arduino Nano so here we go!

The area behind the backglass only needed to be slightly modified to make room for a 3D printed LED holder. I use AutoCAD every day so designing the holder was the easy part. I was able to add a leaf switch to the switch stack on the score reel itself that will stay closed while on the "9" digit. The switch then opens when the reel changes to the "0" digit. My plan was to have the Nano monitor the switch and when it goes from HIGH to LOW it will add to a counter. The Nano will then light the appropriate number of LEDs depending on the counter. I also want to reset the counter whenever a new game is started.

Additionally, I would like to use the pinball machine to power the Arduino. This machine transforms standard US 120VAC into 2 voltages (25VAC and 6VAC) that I can easily tap in to. Any advice on the best way to convert these voltages into something the Nano can use would be great.

So here is where I am on this project. I have the LEDs and score reel switch connected to the Nano and shown in the schematic. I am using a USB adapter for power...a 2A wall wart. This seems to work fine on the test bench but not in the pinball machine. The LEDs light in the correct order but not when I want them to light (they turn on early). I feel like this is a power issue (assuming the code is correct) and the Nano is going from HIGH to LOW too often. I completely took the switch out of the equation with a jumper wire and the results were the same. I have also tried various values for the switch resistor (R10) up to 20k.

My process is as follows:
With everything wired up and the Nano powered on I will manually hit a switch on the pinball playfield worth 5,000 points. I continue to hit the 5,000 point switch and the first LED will light well before the reel gets to the "9" digit. In fact, 5 or more of the LEDs will light up before turning over to "0". What's strange though is that this occurs even when I bypass the switch with a jumper wire. Remember, this is an older machine and there is a lot of vibration and noise when points are registered and a bell clangs each time I hit the 5,000 point switch. Could that have any effect on this since this behavior doesn't occur when idle?
My next step this evening after work was going to be using an old PC power supply to feed 5V to the D13 pin through the switch.

So here is what I am hoping to get some help guidance on:

  1. How does my code look and will it achieve what I am aiming to do?

  2. Does the circuit schematic look correct?

  3. How can I utilize the readily available 25VAC or 6VAC power in the pinball machine?

I hope this is the correct forum for this post.
Thanks,
Robb

// constants won't change:
const int LEDpin1K = 2;     // 100,000 LED
const int LEDpin2K = 3;     // 200,000 LED
const int LEDpin3K = 4;     // 300,000 LED
const int LEDpin4K = 5;     // 400,000 LED
const int LEDpin5K = 6;     // 500,000 LED
const int LEDpin6K = 7;     // 600,000 LED
const int LEDpin7K = 8;     // 700,000 LED
const int LEDpin8K = 9;     // 800,000 LED
const int LEDpin9K = 10;    // 900,000 LED
const int NEWgamepin = 12;  // pin to reset count at start of new game
const int OVERpin = 13;     // score roll-over pin


//Variables will change:
int OVERState;             // variable for reading current state of OVERpin
int lastOVERState = HIGH;  // variable to store previous state of OVERpin (initialized as HIGH)
int k = 0;                 // counting variable
int NEWgame = HIGH;        //New game reset variable

unsigned long lastDebounceTime = 0;  // will store last time LED was updated
const long interval = 500;          // interval to wait before updating "k" count (milliseconds)


void setup() {
  pinMode(LEDpin1K, OUTPUT);  // set LED pins as OUTPUT
  pinMode(LEDpin2K, OUTPUT);
  pinMode(LEDpin3K, OUTPUT);
  pinMode(LEDpin4K, OUTPUT);
  pinMode(LEDpin5K, OUTPUT);
  pinMode(LEDpin6K, OUTPUT);
  pinMode(LEDpin7K, OUTPUT);
  pinMode(LEDpin8K, OUTPUT);
  pinMode(LEDpin9K, OUTPUT);  // set LED pins as OUTPUT

  pinMode(NEWgamepin, INPUT_PULLUP);  // wire this pin to new game relay on pinball machine
  pinMode(OVERpin, INPUT_PULLUP);     // wire this pin to switch1 which triggers when score hits multiples of 100,000
}

void loop() {

  OVERState = digitalRead(OVERpin);  //check the state of OVERpin

  unsigned long currentDebounceTime = millis();
  if (currentDebounceTime - lastDebounceTime >= interval) {
    lastDebounceTime = currentDebounceTime;  // save the last time you lit an LED

    // compare the OVERState to its previous state
    if (OVERState != lastOVERState) {
      lastOVERState = OVERState;  // save the current state as the last state for next time through the loop

      // if the state has changed check if OVERpin is HIGH
      if (OVERState == HIGH) {
        // if the current state is HIGH then switch1 went from closed to open, increment the counter
        k++;
      }
    }
  }

  // NEWgame = digitalRead(NEWgamepin);  //check state of NEWgamepin
  // while (NEWgamepin == HIGH) {
  //   k = 0;        //if NEWgamepin is triggered reset the "k" variable
  //   delay(5000);  //stop reading for a bit to allow pinball machine to cycle through the start-up procedure
  // }

  // Light the correct LED's to indicate rollover score

  if (k >= 10) k = 0;  //start lights over after reaching 10x multiples of a million

  if (k <= 0) {  //  No lights on
    digitalWrite(LEDpin1K, LOW);
    digitalWrite(LEDpin2K, LOW);
    digitalWrite(LEDpin3K, LOW);
    digitalWrite(LEDpin4K, LOW);
    digitalWrite(LEDpin5K, LOW);
    digitalWrite(LEDpin6K, LOW);
    digitalWrite(LEDpin7K, LOW);
    digitalWrite(LEDpin8K, LOW);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 1) {  //  100,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, LOW);
    digitalWrite(LEDpin3K, LOW);
    digitalWrite(LEDpin4K, LOW);
    digitalWrite(LEDpin5K, LOW);
    digitalWrite(LEDpin6K, LOW);
    digitalWrite(LEDpin7K, LOW);
    digitalWrite(LEDpin8K, LOW);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 2) {  //  200,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, HIGH);
    digitalWrite(LEDpin3K, LOW);
    digitalWrite(LEDpin4K, LOW);
    digitalWrite(LEDpin5K, LOW);
    digitalWrite(LEDpin6K, LOW);
    digitalWrite(LEDpin7K, LOW);
    digitalWrite(LEDpin8K, LOW);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 3) {  //  300,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, HIGH);
    digitalWrite(LEDpin3K, HIGH);
    digitalWrite(LEDpin4K, LOW);
    digitalWrite(LEDpin5K, LOW);
    digitalWrite(LEDpin6K, LOW);
    digitalWrite(LEDpin7K, LOW);
    digitalWrite(LEDpin8K, LOW);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 4) {  //  400,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, HIGH);
    digitalWrite(LEDpin3K, HIGH);
    digitalWrite(LEDpin4K, HIGH);
    digitalWrite(LEDpin5K, LOW);
    digitalWrite(LEDpin6K, LOW);
    digitalWrite(LEDpin7K, LOW);
    digitalWrite(LEDpin8K, LOW);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 5) {  //  500,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, HIGH);
    digitalWrite(LEDpin3K, HIGH);
    digitalWrite(LEDpin4K, HIGH);
    digitalWrite(LEDpin5K, HIGH);
    digitalWrite(LEDpin6K, LOW);
    digitalWrite(LEDpin7K, LOW);
    digitalWrite(LEDpin8K, LOW);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 6) {  //  600,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, HIGH);
    digitalWrite(LEDpin3K, HIGH);
    digitalWrite(LEDpin4K, HIGH);
    digitalWrite(LEDpin5K, HIGH);
    digitalWrite(LEDpin6K, HIGH);
    digitalWrite(LEDpin7K, LOW);
    digitalWrite(LEDpin8K, LOW);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 7) {  //  700,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, HIGH);
    digitalWrite(LEDpin3K, HIGH);
    digitalWrite(LEDpin4K, HIGH);
    digitalWrite(LEDpin5K, HIGH);
    digitalWrite(LEDpin6K, HIGH);
    digitalWrite(LEDpin7K, HIGH);
    digitalWrite(LEDpin8K, LOW);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 8) {  //  800,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, HIGH);
    digitalWrite(LEDpin3K, HIGH);
    digitalWrite(LEDpin4K, HIGH);
    digitalWrite(LEDpin5K, HIGH);
    digitalWrite(LEDpin6K, HIGH);
    digitalWrite(LEDpin7K, HIGH);
    digitalWrite(LEDpin8K, HIGH);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 9) {  //  900,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, HIGH);
    digitalWrite(LEDpin3K, HIGH);
    digitalWrite(LEDpin4K, HIGH);
    digitalWrite(LEDpin5K, HIGH);
    digitalWrite(LEDpin6K, HIGH);
    digitalWrite(LEDpin7K, HIGH);
    digitalWrite(LEDpin8K, HIGH);
    digitalWrite(LEDpin9K, HIGH);
  }
}

No, that will not do the job.
Use INPUT_PULLUP for the two inputs. Connect each switch between input pin and GND.
Use debouncing code to handle the switches.

1 Like

120vac? 12? 48? 24?

This machine transforms standard US 120VAC into 2 voltages (25VAC and 6VAC) that I can easily tap in to.

Thanks, I edited the question to be more clear.

It all begins with 'rectification' (probably that 6vac), followed by 'regulation'.

Use the 120 VAC to feed standard power supplies. 6 V AC is not enough for a safe, ripple free generation of 5 volt. Use a 120 V AC to 5 V DC supply.

I do have an old switching power supply that I removed from an arcade machine that should work for that purpose. Those are handy since they have AC terminals and I won't need to run another cord to an outlet. Thanks!
Does anyone have any ideas on how I could utilize the 6VAC in other ways? For example, when the pinball machine "Game Over" light turns on, my new LEDs enter "attract mode" and randomly flash.

Hello
You are happy with your sketch or do think about to streamline the code ?

Not really. It's not good for anything but bulbs.
Detecting Game Over etc...... Use a serial diode + serial resistor fed into an opto coupler. The other side of the opto pulls down an INPUT_PULLUP input on the controller.....

1 Like

So here is what I came up with during lunch today. Does this seem like it will work?
Thanks again!

// constants won't change:
const int LEDpin1K = 2;     // 100,000 LED
const int LEDpin2K = 3;     // 200,000 LED
const int LEDpin3K = 4;     // 300,000 LED
const int LEDpin4K = 5;     // 400,000 LED
const int LEDpin5K = 6;     // 500,000 LED
const int LEDpin6K = 7;     // 600,000 LED
const int LEDpin7K = 8;     // 700,000 LED
const int LEDpin8K = 9;     // 800,000 LED
const int LEDpin9K = 10;    // 900,000 LED
const int NEWgamepin = 12;  // pin to reset count at start of new game
const int OVERpin = 13;     // score roll-over pin


//Variables will change:
int OVERState;             // variable for reading current state of OVERpin
int lastOVERState = HIGH;  // variable to store previous state of OVERpin (initialized as HIGH)
int k = 0;                 // counting variable
int NEWgame = HIGH;        //New game reset variable

unsigned long lastDebounceTime = 0;  // will store last time LED was updated
const long interval = 500;          // interval to wait before updating "k" count (milliseconds)


void setup() {
  pinMode(LEDpin1K, OUTPUT);  // set LED pins as OUTPUT
  pinMode(LEDpin2K, OUTPUT);
  pinMode(LEDpin3K, OUTPUT);
  pinMode(LEDpin4K, OUTPUT);
  pinMode(LEDpin5K, OUTPUT);
  pinMode(LEDpin6K, OUTPUT);
  pinMode(LEDpin7K, OUTPUT);
  pinMode(LEDpin8K, OUTPUT);
  pinMode(LEDpin9K, OUTPUT);  // set LED pins as OUTPUT

  pinMode(NEWgamepin, INPUT_PULLUP);  // wire this pin to new game relay on pinball machine
  pinMode(OVERpin, INPUT_PULLUP);     // wire this pin to switch1 which triggers when score hits multiples of 100,000
}

void loop() {

  OVERState = digitalRead(OVERpin);  //check the state of OVERpin

  unsigned long currentDebounceTime = millis();
  if (currentDebounceTime - lastDebounceTime >= interval) {
    lastDebounceTime = currentDebounceTime;  // save the last time you lit an LED

    // compare the OVERState to its previous state
    if (OVERState != lastOVERState) {
      lastOVERState = OVERState;  // save the current state as the last state for next time through the loop

      // if the state has changed check if OVERpin is HIGH
      if (OVERState == HIGH) {
        // if the current state is HIGH then switch1 went from closed to open, increment the counter
        k++;
      }
    }
  }

  // NEWgame = digitalRead(NEWgamepin);  //check state of NEWgamepin
  // while (NEWgamepin == HIGH) {
  //   k = 0;        //if NEWgamepin is triggered reset the "k" variable
  //   delay(5000);  //stop reading for a bit to allow pinball machine to cycle through the start-up procedure
  // }

  // Light the correct LED's to indicate rollover score

  if (k >= 10) k = 0;  //start lights over after reaching 10x multiples of a million

  if (k <= 0) {  //  No lights on
    digitalWrite(LEDpin1K, LOW);
    digitalWrite(LEDpin2K, LOW);
    digitalWrite(LEDpin3K, LOW);
    digitalWrite(LEDpin4K, LOW);
    digitalWrite(LEDpin5K, LOW);
    digitalWrite(LEDpin6K, LOW);
    digitalWrite(LEDpin7K, LOW);
    digitalWrite(LEDpin8K, LOW);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 1) {  //  100,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, LOW);
    digitalWrite(LEDpin3K, LOW);
    digitalWrite(LEDpin4K, LOW);
    digitalWrite(LEDpin5K, LOW);
    digitalWrite(LEDpin6K, LOW);
    digitalWrite(LEDpin7K, LOW);
    digitalWrite(LEDpin8K, LOW);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 2) {  //  200,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, HIGH);
    digitalWrite(LEDpin3K, LOW);
    digitalWrite(LEDpin4K, LOW);
    digitalWrite(LEDpin5K, LOW);
    digitalWrite(LEDpin6K, LOW);
    digitalWrite(LEDpin7K, LOW);
    digitalWrite(LEDpin8K, LOW);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 3) {  //  300,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, HIGH);
    digitalWrite(LEDpin3K, HIGH);
    digitalWrite(LEDpin4K, LOW);
    digitalWrite(LEDpin5K, LOW);
    digitalWrite(LEDpin6K, LOW);
    digitalWrite(LEDpin7K, LOW);
    digitalWrite(LEDpin8K, LOW);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 4) {  //  400,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, HIGH);
    digitalWrite(LEDpin3K, HIGH);
    digitalWrite(LEDpin4K, HIGH);
    digitalWrite(LEDpin5K, LOW);
    digitalWrite(LEDpin6K, LOW);
    digitalWrite(LEDpin7K, LOW);
    digitalWrite(LEDpin8K, LOW);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 5) {  //  500,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, HIGH);
    digitalWrite(LEDpin3K, HIGH);
    digitalWrite(LEDpin4K, HIGH);
    digitalWrite(LEDpin5K, HIGH);
    digitalWrite(LEDpin6K, LOW);
    digitalWrite(LEDpin7K, LOW);
    digitalWrite(LEDpin8K, LOW);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 6) {  //  600,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, HIGH);
    digitalWrite(LEDpin3K, HIGH);
    digitalWrite(LEDpin4K, HIGH);
    digitalWrite(LEDpin5K, HIGH);
    digitalWrite(LEDpin6K, HIGH);
    digitalWrite(LEDpin7K, LOW);
    digitalWrite(LEDpin8K, LOW);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 7) {  //  700,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, HIGH);
    digitalWrite(LEDpin3K, HIGH);
    digitalWrite(LEDpin4K, HIGH);
    digitalWrite(LEDpin5K, HIGH);
    digitalWrite(LEDpin6K, HIGH);
    digitalWrite(LEDpin7K, HIGH);
    digitalWrite(LEDpin8K, LOW);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 8) {  //  800,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, HIGH);
    digitalWrite(LEDpin3K, HIGH);
    digitalWrite(LEDpin4K, HIGH);
    digitalWrite(LEDpin5K, HIGH);
    digitalWrite(LEDpin6K, HIGH);
    digitalWrite(LEDpin7K, HIGH);
    digitalWrite(LEDpin8K, HIGH);
    digitalWrite(LEDpin9K, LOW);
  }

  if (k == 9) {  //  900,000 light on
    digitalWrite(LEDpin1K, HIGH);
    digitalWrite(LEDpin2K, HIGH);
    digitalWrite(LEDpin3K, HIGH);
    digitalWrite(LEDpin4K, HIGH);
    digitalWrite(LEDpin5K, HIGH);
    digitalWrite(LEDpin6K, HIGH);
    digitalWrite(LEDpin7K, HIGH);
    digitalWrite(LEDpin8K, HIGH);
    digitalWrite(LEDpin9K, HIGH);
  }
}

It's funny, my initial hope was that I could get the code working on my own and then I was going to post here for tips on how to streamline.
So yes, I am always up for learning more efficient ways to do things.

Hello
That´s fine. I will take a view into my sketch box to mod a smilar sketch.
The mods will be done in C++. :nerd_face:

It looks like it will only check the OVER switch every half second. Unless the OVER switch always stays closed for more than half a second you could miss it.

void loop() {
  unsigned long currentTime = millis();

  OVERState = digitalRead(OVERpin);  //check the state of OVERpin

    if (OVERState != lastOVERState && currentTime - lastDebounceTime >= interval) {
      lastDebounceTime = currentTime;  // save the last time you lit an LED
      lastOVERState = OVERState;  // save the current state as the last state for next time through the loop

      // if the state has changed check if OVERpin is HIGH
      if (OVERState == HIGH) {
        // if the current state is HIGH then switch1 went from closed to open, increment the counter
        k++;
      }
    }
  }
}

The code is good regarding the inputs. I hope You noted the change needed for the button connections, between the input pin and GND....

The debounce time of 500 mS will surely cover the bumps in the switch! I suppose You don't score 100 000 within that time...

I havent't analyzed the rest of the code much.
As already suggested You can simplify the code. In setup, and in New game, You inactivate all the 100 000 indicators, digitalWrite(pinX, LOW);.
Then:

if (k > 0 ) digitalWrite(LEDpin1K, HIGH);
if (k > 1 ) digitalWrite(LEDpin2K, HIGH);
if (k > 2 ) digitalWrite(LEDpin3K, HIGH);
if (k > 3 ) digitalWrite(LEDpin4K, HIGH);
if (k > 4 ) digitalWrite(LEDpin5K, HIGH);
if (k > 5 ) digitalWrite(LEDpin6K, HIGH);
if (k > 6 ) digitalWrite(LEDpin7K, HIGH);
if (k > 7 ) digitalWrite(LEDpin8K, HIGH);
if (k > 8 ) digitalWrite(LEDpin9K, HIGH);

If You like the idea...

What are the voltages I should be getting between D13 and GND in both HIGH and LOW state?

Hello and good morning
Here comes the "slimmed down" sketch for your pinball machine.
What is made:

  1. packed all pins into arrays
  2. declaration and definition of a structure for the buttons
  3. added a timer to debounce the buttons
// BLOCK COMMENT
// ATTENTION: This Sketch contains elements of C++.
// https://www.learncpp.com/cpp-tutorial/
// https://forum.arduino.cc/t/score-counter-for-pinball-machine/909522
#define ProjectName "Score counter for pinball machine"
// CONSTANT DEFINITION
// you may need to change these constants to your hardware and needs.
constexpr byte Input_[] {A0, A1};  // portPin o---|button|---GND
constexpr byte Output_[] {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};		 // portPin o---|220|---|LED|---GND
constexpr unsigned long ButtonScanTime {20};
// VARIABLE DECLARATION AND DEFINTION
enum {NEWgamepin , OVERpin};
unsigned long currentTime;
struct BUTTON { // a button has a ....
  byte name_;
  byte pin;
  bool state_;
} buttons[] { // the following buttons are initialized 
  {NEWgamepin, Input_[NEWgamepin], false}, // new game button and
  {OVERpin, Input_[OVERpin], false},       // and over button
};
struct TIMER { // a timer has 
  unsigned long duration;
  unsigned long stamp;
};
TIMER buttonScan{ButtonScanTime, 0}; // the buttonScan timer is initialized 

// FUNCTIONS
bool checkTimer(TIMER & time_) {  // generic time handler using TIME struct
  if (currentTime - time_.stamp >= time_.duration ) {
    time_.stamp = currentTime;
    return true;
  } else return false;
}
void setup() {
  Serial.begin(9600);
  Serial.println(F("."));
  Serial.print(F("File   : ")), Serial.println(__FILE__);
  Serial.print(F("Date   : ")), Serial.println(__DATE__);
  Serial.print(F("Project: ")), Serial.println(ProjectName);
  pinMode (LED_BUILTIN, OUTPUT);
  for (auto Input : Input_) pinMode(Input, INPUT_PULLUP);
  for (auto Output : Output_) pinMode(Output, OUTPUT);
  // check outputs
  for (auto Output : Output_) digitalWrite(Output, HIGH);
  delay(1000);
  for (auto Output : Output_) digitalWrite(Output, LOW);
}
void loop () {
  currentTime = millis();
  digitalWrite(LED_BUILTIN, (currentTime / 500) % 2);
  if (checkTimer(buttonScan)) {
    for (auto &button_ : buttons) {
      bool stateNew = !digitalRead(button_.pin);
      if (button_.state_ != stateNew) {
        button_.state_ = stateNew;
        if (stateNew) {
          static int number = 0;
          switch (button_.name_) {
            case NEWgamepin:
              Serial.println("NEWgamepin");
              number = 0;
              for (auto Leds : Output_) digitalWrite(Leds, LOW);
              break;
            case OVERpin:
              Serial.println("OVERpin");
              digitalWrite (Output_[number], HIGH);
              number++;
              number = number % (sizeof(Output_) / sizeof(Output_[0]));
              if (!number)  for (auto Leds : Output_) digitalWrite(Leds, LOW);
              break;
          }
        }
      }
    }
  }
}

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

1 Like

Wow, amazing! Thank you so much.
I have a few Nano's laying around so I will be able to upload this and play around with both codes.
Robb

Hello
Don´t hesitate to ask in case of some questions or mods to this sketch.

I uploaded the new code and wired the switch to D13 and GND but had no LEDs turn on. I didn't have much time to troubleshoot last night beyond making sure the connections were sound. I also took some voltage readings at the input pin HIGH and LOW states. It was basically 0V at LOW but only 1.8V at HIGH. This seems too low?
How important is the resistor at D13? I had no resistor there once and a 3.9k for a second run with no voltage changes. That was all the time I had yesterday but am hoping to get it working this afternoon. Am I missing something obvious?

Thanks,
Robb

I hope You removed that R10 resistor and put it on the shelf..
Did You make any tries with the button?
I don't get Your message...
To be sure, please post the code of today when You reply.