Shuffle Board Scoreboard

I have seen 2 strings about this subject, both now closed and neither any help for an absolute beginner. I did a little Fortran 55 years ago, career as mech eng. I want to replace all the electro/mech devices with Arduino and LEDs. All games will be to 21 so no choices there. I need to light 1-9, 10, and 20. I've replaced the inc bulbs with LEDs, looks great. I want existing momentary contact switches to increment the score so #1 on, all others off; 2 on all others off, etc to 11 when #1 and #10 must be on, etc to 21. So one difficulty for me is to keep the LED on after the MC switch is released. Also it would be nice to be able to go backward in case a player pushes too many times.
To be honest, I'm hoping someone has already done this and will send me their program! Then I can get back to my model train layout.
All help greatly appreciated!

This is to bad, you had an opportunity to learn something :frowning:

Then you could apply what you learn to the train project.

Hello dannc

Consider.

#define ProjectName "RADIOBUTTONS"
/* BLOCK COMMENT
  -
  https://europe1.discourse-cdn.com/arduino/original/4X/7/e/0/7e0ee1e51f1df32e30893550c85f0dd33244fb0e.jpeg
*/
// make structures
struct TIMER
{
  uint32_t intervalMillis;
  uint32_t previousMillis;
};
struct RADIOBUTTON
{
  const uint8_t Knop;
  const uint8_t Led;
  uint8_t   stateOld;
  TIMER debounce;
} radioButtons[]
{
  {A0, 9, LOW, 20, 0},
  {A1, 10, LOW, 20, 0},
  // add button/led combinations as you like
};
// 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__);
  for (auto &radioButton : radioButtons)
  {
    pinMode(radioButton.Knop, INPUT_PULLUP);
    pinMode(radioButton.Led, OUTPUT);
    digitalWrite(radioButton.Led, HIGH);
    delay(1000);
  }
}
void loop()
{
  uint32_t currentMillis = millis();
  heartBeat(LED_BUILTIN, currentMillis);

  for (auto &radioButton : radioButtons)
  {
    if(currentMillis-radioButton.debounce.previousMillis >= radioButton.debounce.intervalMillis)
    {
      radioButton.debounce.previousMillis = currentMillis;
      uint8_t stateNew=digitalRead(radioButton.Knop)?LOW:HIGH;
      if (radioButton.stateOld!=stateNew) 
      {
        radioButton.stateOld=stateNew;
        if (stateNew==HIGH) 
        {
          for (auto &radioButton : radioButtons) digitalWrite(radioButton.Led,LOW);
          digitalWrite(radioButton.Led,HIGH);
        }
      }
    }
  }
}
//------------------------------------------------------------

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

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.