Code or Equipment Problem

Hey guys,

I'm a little new to coding, and I'm trying to create a dart game scoreboard. Long story short, I need one button to light up 3 different LED's; one by itself, then two, then all three all together. I am wondering if this could be done by an regular push button, if it can be done by messing around with the coding, or if you had any other suggestions on how to get this done.

That could easily be done with a button and a state machine that chosses the state based on the button push count. Look at the state change detection example in the IDE and there are numerous state machine tutorials.

That sounds like a great introductory project for an Arduino. You are going to learn very quickly by starting with something like that.

First, you need some hardware: a button and 3 lights. LEDs are the easiest lights but you do need a resistor for each LED. 220 ohms is a good value to start with - less ohms will make the LED brighter. Connect each LED+resistor to one Arduino pin and ground. Connect the button between a fourth Arduino pin and ground.

Start with the example ‘blink’ sketch. See if you can make each LED blink on its own. Make them all blink together.

Next check your button is working - change the sketch to read the input pin and turn on the LEDs when it is pushed down.

The next part jumps in difficulty: detecting a button-push event. The reason this is difficult is that real buttons ‘bounce’ and you can get 5-50 on+off cycles when your finger hits the button. For something this simple, a simple time delay will work. After you detect that the button has been pushed, then delay a few milliseconds before looking at the button input again.

Start hacking on the blink sketch and post your code here if you have any problems.

josh-s: Hey guys,

I'm a little new to coding, and I'm trying to create a dart game scoreboard. Long story short, I need one button to light up 3 different LED's; one by itself, then two, then all three all together. I am wondering if this could be done by an regular push button, if it can be done by messing around with the coding, or if you had any other suggestions on how to get this done.

Each button press increments a variable and count goes from 0, to 1, to 2, to 3, and back to 0. In a switch-case (or extended if) you check the variable value. If 0, all LEDs are switched off. If the value of 1, you turn on the 1st LED. If the value is 2, you turn on the #2 LED (#1 is already on). If the value is 3, you turn on LED #3 (#1 and #2 are already on). If the value is 4, you make the value 0 and loop back where value is checked for 0... Bam! You turn off #1, #2, and #3.

Got it? Now translate to code. Remember, each LED needs a current limiting resistor and be certain to keep the combined current of LEDs 1+2+3 under the total current for the atmega. (Read This.)

Ray

Hey guys,

I'm a little new to coding, and I'm trying to create a dart game scoreboard. Long story short, I need one button to light up 3 different LED's; one by itself, then two, then all three all together. I am wondering if this could be done by an regular push button, if it can be done by messing around with the coding, or if you had any other suggestions on how to get this done.

Of course you can but what has this to do with darts? How many LEDs do you have in total?

@MorganS the project is going to require 14 buttons each controlling 3 LED's on its own (making 42 LED's). I purchased the Arduino Dre, will that have enough pins to control all the buttons and LED's?

@KenF I have 14 buttons, each controlling 3 LED's. 42 LED's total.

How are you connecting the 42 LEDs? Are they each connected to their own individual pin?

KenF: How are you connecting the 42 LEDs? Are they each connected to their own individual pin?

Yes, using the Arduino Dre.

Hi, looks like a lot of I/O, so you will have to use extra hardware to help with the project.
What is the dart game exactly, it doesn’t sound like 500 and down, 180 etc.
If we know what the LEDs are going to represent we may be able to give you some alternative display methods.

Tom… :slight_smile:

I’d probably organise it something like this

struct dGroup;
void showLeds (dGroup groupObj);

struct dGroup
  {
   const byte buttonPin;
   const byte leds[3];
   byte value;
   byte priorState;
  };
  
dGroup myGroups[2]={
1,2,3,4,0,0,  //button on pin 1, controls leds on pins 2,3 and 4
6,7,8,9,0,0   //button on pin 6, controls leds on pins 7,8 and 9
//etc...

};

int groupCount;
void setup()
{
groupCount=sizeof(myGroups) / sizeof(dGroup);

for(int n=0;n< groupCount;n++)
  {
  pinMode(myGroups[n].buttonPin,INPUT_PULLUP);
  for(int m=0;m<3;m++)
     pinMode(myGroups[n].leds[m],OUTPUT);  
  showLeds (myGroups[n]);
  }

}
void loop()
{
for(int n=0;n < groupCount; n++)
  {
   bool buttonState=digitalRead(myGroups[n].buttonPin);
   if(buttonState !=myGroups[n].priorState)
     {
      myGroups[n].value ++;
      if(myGroups[n].value >3)
          myGroups[n].value=0;
      showLeds(myGroups[n]);
      myGroups[n].priorState=buttonState;
     }
  }
}

void showLeds (dGroup groupObj)
{
for(int n=0;n<3; n++)
  {
  if (groupObj.value > n)
    digitalWrite(groupObj.leds[n], HIGH);
  else
    digitalWrite(groupObj.leds[n], LOW); 
  }
}

@KenF I'll try it out, thanks!

@TomGeorge It's called cricket. You need to hit three 20's, 19's, 18's, 17's, 16's, 15's and bullseyes. Each LED will just represent a dart hit in each section.

josh-s: @KenF I'll try it out, thanks!

Did I mention it's totally untested! I was intending to convey a concept, rather than a solution.

@TomGeorge It's called cricket. You need to hit three 20's, 19's, 18's, 17's, 16's, 15's and bullseyes. Each LED will just represent a dart hit in each section.

@KenF Yeah, i figured that. I knew you were good, but I didnt figure you were good enough to know what buttons/LED's are in what pins. ;)

josh-s: @KenF Yeah, i figured that. I knew you were good, but I didnt figure you were good enough to know what buttons/LED's are in what pins. ;)

And whether your buttons are active HIGH or LOW and whether you're connecting to the LEDS annodes or cathodes.

I'd suggest you try getting it working for just a couple of buttons first and then you just need to alter the array to add all the others.

@KenF If i'm not using a breadboard, how do I ground all 42 LED's?

josh-s: @KenF If i'm not using a breadboard, how do I ground all 42 LED's?

By hook or by crook.

Do you, by any chance, have any old IDE hard drive or floppy drive cables around? If so these can be used almost like mini breadboards. On one end connect your LEDs, on the other push some pins in every hole on one side, Run a wire between them (and soldered to each), this then becomes your common ground. You can then use jumper wires from the other side to their respective pins.