Go Down

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

koolcube1

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!

CrossRoads

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. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

koolcube1

Well, I saw this video and i think i need just that kind of set up.

http://www.youtube.com/watch?v=rcoI_w_80zk

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

CrossRoads

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

Code: [Select]

/* 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
   
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

koolcube1

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

CrossRoads

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. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

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.

Runaway Pancake


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!
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

CrossRoads

I think this matches the pinout described in the sketch.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

koolcube1

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

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.

CrossRoads

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. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

koolcube1

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.

CrossRoads

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. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

koolcube1

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

Go Up