LED DIGITAL NUMERIC DISPLAY AND LED COUNTER

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!

So you need a keypad to input numbers, and a 7-segment display to show the numbers, and 1-9 LEDs to light up?

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

I think this will do it.
Little confused about counting 0 to 9, yet having 10 LEDs?

/* toy for counting
Needs 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=8
Needs 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,g
byte 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

sorry actually, its counting from 0-10 and i will get a two character 7 segment numeric display.

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.

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.

koolcube1:
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.

Click Here!

I think this matches the pinout described in the sketch.

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.

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.

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.

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.

It is not a final layout, it is just meant to give you the idea of how things will connect.

Please can you give a final layout. i just got done putting everything together. Please help

I layed out my Radioshack 7 segment led this way 7 segment LED Radio shack version
then im going to connect the other leds like you have on your schematic and try and make it work. any guidiance will be appreciated. Thanks

Looking good. I didn't know fritzing did looping wires. That makes it easier to see.
Keep plugging along!

Thanks!
So far this is how far i've gotten

I'm not really sure what to do next. so i'm awaiting more guidance. Ive uploaded the unfinished .fzz format. if you could please help complete it i'd be very greatful

led counting toy.fzz (9.37 KB)

Keep on going. Read the sketch, it defines which D#s go to resistors (or A#s - A0 = D14, A1 = D15, ... A5 = D19) , the other side of resistor goes to long lead of the LED, the short leg goes to an outer common rail that connects to Arduino Gnd along with the common cathode from the Display.
The Momentary contact/normally open Switch/button has one lead connected to Gnd, the other to the pin called out in the sketch.