Pages: [1] 2 3   Go Down
Author Topic: LED DIGITAL NUMERIC DISPLAY AND LED COUNTER  (Read 3301 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26554
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26554
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
/* 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
   
Logged

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26554
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Edison Member
*
Karma: 64
Posts: 2465
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

"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?"

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26554
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think this matches the pinout described in the sketch.


* 7segment-LEDs-button.jpg (64.5 KB, 960x720 - viewed 42 times.)
Logged

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26554
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


* Display_LEDs.jpg (77.51 KB, 960x720 - viewed 37 times.)
Logged

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26554
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1] 2 3   Go Up
Jump to: