Go Down

### Topic: LED DIGITAL NUMERIC DISPLAY AND LED COUNTER (Read 12447 times)previous topic - next topic

#### koolcube1

##### May 26, 2013, 04:22 am
As a newbie
I'm trying to assemble a simple project on the arduino that can count LED's.
say if i input 2 in the LED numeric display, it will light up 2 leds. if i input 5, it will light up 5 leds.
how can i do this and codes too. Thank you!

#1
##### May 26, 2013, 04:33 am
So you need a keypad to input numbers, and a 7-segment display to show the numbers, and 1-9 LEDs to light up?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### koolcube1

#2
##### May 26, 2013, 05:32 am
Well, I saw this video and i think i need just that kind of set up.

one button to do the counting should be ok. i want to have 10 LEDS.
each time i push the button it will increase the number on the display and correspondingly light up the amount of LED's.
Just a simple toy to get my 3-year old interested in counting. Thank you

#3
##### May 26, 2013, 07:41 am
I think this will do it.
Little confused about counting 0 to 9, yet having 10 LEDs?

Code: [Select]
`/* toy for countingNeeds common cathode 7 segment display, 7 current limit resistors, wired from pins 2-3-4-5-6-7-8 to anodes. Cathode to Gnd.A=2, B=3, C=4, D=5, E=6, F=7. G=8Needs 10 LEDs, 10 current limit resistors, resistors wired from pins 9-10-11-12-13-14-15-16-17-18 to anodes, cathodes to Gnd.Needs momentary, normally open switch wired from pin 19 to Gnd.Pins 0,1 used for serial downloads*/byte segmentArray [] = {2,3,4,5,6,7,8}; // a,b,c,d,e,f,gbyte fontArray[] = {  B00111110, // 0 dp-g-f-e-d-c-b-a  B00000110, // 1  B01011011, // 2  B01001111, // 3  B01100110, // 4  B01011011, // 5  B01111101, // 6  B00000111, // 7  B01111111, // 8  B01100111, // 9};byte ledArray[] = {9,10,11,12,13,14,15,16,17,18,}; // 0-9 - why have 10?byte buttonPin = 19;byte x;byte count;byte bitPlace;void setup(){  // set pins as outputs  for (x = 2; x<19; x=x+1){    pinMode (x, OUTPUT);  }  pinMode (buttonPin, INPUT);  digitalWrite (buttonPin, HIGH);  // internal pullup enabled      Serial.begin(9600);}void loop(){  if(digitalRead(buttonPin) == LOW){    count = count+1;    if (count == 10){      count = 0;    }      bitPlace = 1;      for (x=0; x<8; x=x+1){         // set a pin high if bitmask == 1 and fontArray has a 1 in that place        digitalWrite (segmentArray[x], (bitPlace & fontArray[count]) );        bitPlace = bitPlace <<1; // next bit      } // end 7-segment display writes    // set individual LEDs high/low    for (x=0; x<10; x=x+1){      if (x<=count){        digitalWrite (ledArray[x],  HIGH);      }      else {        digitalWrite(ledArray[x], LOW);      }    }  // end single LED writes    delay (100); // debounce button  } // end button check  } // end loop    `
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### koolcube1

#4
##### May 26, 2013, 09:44 pm
sorry actually, its counting from 0-10 and i will get a two character 7 segment numeric display.

#5
##### May 26, 2013, 10:42 pm
You need extra hardware then, you are out of pins. Need two more to be able to select one digit or the other.
Adding 4 TPIC6B595s would allow easy driving of 14 segments and 10 LEDs.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### koolcube1

#6
##### May 26, 2013, 11:14 pm
ok. i will just count to 5 for now just to get an understanding of how it works. i got the 7 segment numeric display and resistors. how do i connect them? Thank you.

#### runaway_pancake

#7
##### May 26, 2013, 11:52 pm

ok. i will just count to 5 for now just to get an understanding of how it works. i got the 7 segment numeric display and resistors. how do i connect them? Thank you.

"Who is like unto the beast? who is able to make war with him?"
When all else fails, check your wiring!

#8
##### May 27, 2013, 01:09 am
I think this matches the pinout described in the sketch.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### koolcube1

#9
##### May 27, 2013, 04:51 am
THANK YOU VERY MUCH MR. CROSSROAD!
I have no idea or understanding of such schematic. Could you please show me on a breadboard please?? if that's not too much to ask.

#### koolcube1

#10
##### May 27, 2013, 05:22 am
Mind you i am using the radio shack numeric display. i understand it is kind of different from the other leds so the wiring might be different. Thank you.

#11
##### May 27, 2013, 06:32 am
You're gonna make connections like this. The rails along the side are in common, the groups of 5 going across common.
Use the rails so you don't have to make as many individual connections.
This tool won't let me show the LEDs from the 5-pin holes to the outer rail. Connect the short leg/flat spot on the body to a rail and connect that rail to a Gnd pin. Same with the common cathode on the display. You'll have to read the display spec to see which pin(s) that is, same for the A-B-C-D-E-F-G pins.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### koolcube1

#12
##### May 27, 2013, 10:15 pm
This doesnt show the position of the switch. And i am just using 5 leds.
Also i'm sure i'd have to modify the code a little bit. Thanks for the effort.

#13
##### May 28, 2013, 12:12 am
It is not a final layout, it is just meant to give you the idea of how things will connect.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#14