Loading...
Pages: 1 2 [3]   Go Down
Author Topic: NOOB needs help (7 segment countdown)  (Read 3172 times)
0 Members and 1 Guest are viewing this topic.
Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1233
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just finish a 2 digit multiplexer program. It just count up from 0 to 99 and repeat. I did use the BCD converter routine and my LED display routine. And just I said some FOR ( x=0;x<10;x++) statements. It is not test yet and with no comments. Anyway here is the code and let me know of what you think. I just hope it help others.  smiley
Code:
/*
size = 1432

Here a program to multiplex two LED display.
It will count from 0 to 99.

Parts:

1 - 7447 BCD to LED display decoder
1 - 330 ohms resistor network - 14 pins
or
7 - 330 ohms resistor
1 double common anode LED display
or
2 double common anode LED display
2 - PNP - 2N3906 transistor
2 - 1 k resistor.

Not tested yet. No comments yet.

Program by Serge J Desjardins <-- techone 
Toronto, Ontario, Canada
*/

const int led[6] = {9,10,11,12,8,7};

int pin;
int counting;
int dataone;
int datatwo;
int storage;
int looping;
 
void setup()

{
  for (pin =0; pin < 6; pin++ )
   {
     pinMode (led[pin], OUTPUT);
   }   
}

void loop()

{
 for (counting=0; counting<100; counting++)
 {
  BCDconverter();
  for (looping=0; looping<25000; looping++)
  {
    storage=dataone;
    displaydigit();
    digitalWrite (led[4],HIGH);
    digitalWrite (led[5], LOW);
    delay(17);
    storage=datatwo;
    displaydigit();
    digitalWrite (led[5],HIGH);
    digitalWrite (led[4], LOW);
    delay(17);   
  }     
 } 
 
}

void BCDconverter()

{
  dataone=counting/10;
  datatwo=counting % 10;
}

void displaydigit()

{
  boolean A=bitRead(storage,3);
  boolean B=bitRead(storage,2);
  boolean C=bitRead(storage,1);
  boolean D=bitRead(storage,0);
 
  digitalWrite (led[3], A);
  digitalWrite (led[2], B);
  digitalWrite (led[1], C);
  digitalWrite (led[0], D);
 

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void displaydigit()

{
  boolean A=bitRead(storage,3);
  boolean B=bitRead(storage,2);
  boolean C=bitRead(storage,1);
  boolean D=bitRead(storage,0);
 
  digitalWrite (led[3], A);
  digitalWrite (led[2], B);
  digitalWrite (led[1], C);
  digitalWrite (led[0], D);
 

couple of things there;
1)"bitRead" doesn't return a "boolean"
2) "digitalWrite" takes an "int", not a "boolean".

Code:
void displaydigit()
{
  for (int i = 0; i < 4; ++i {
   digitalWrite (led[i], bitRead(storage,i));
  }
Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1233
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1st.. Thank AWOL for the new, efficient routine by using the FOR statement. It does eliminate repetitions. Specially if I need to use 8 bits or more bits.  Example : Using Arduino to program an EPROM.

2nd.. I use boolean is because in digitalWrite ( pin#, HIGH ) or digitalWrite( pin# , LOW )  HIGH or LOW is a boolean value ---> 1 or 0

3rd.. I use bitread to isolate the bit I want to display whatever is 1 or 0.

Anyway thank AWOL for the new routine. I will use it. 
Logged

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1233
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys, I just finish to re-design and refine my 2 digit multiplex program. The program work, I "fine tune" it and with some modifications could be use for count down or display multidigit system ex: 8 display During testing, the Ardiuno just keep reset ( due to low power/current ) so please use a seperated power line ( +5 V ) if using a 7447 or 7448 chip. If using a CMOS type ( a 4000 series chips ) you can use the 9V ( going into the Ardiuno board ) And of course connect the ground from the Ardiuno to the circuit.

Here the code. I hope it help in some of your designs.

Code:
/*
size = 1420

Version 1.6

Here a program to multiplex two seven-seqment LED display.
It will count from 0 to 99.

Tested and Worked

Parts:

1 - 7447 BCD to LED display decoder
1 - 330 ohms resistor network - 14 pins
or
7 - 330 ohms resistor
1 double common anode or cathode 7 segment LED display
or
2 double common anode or cathode 7 segment LED display
2 - PNP - 2N3906 transistor for commun anode
2 - NPN - 2N3906 transistor for commun cathode
2 - 1 k resistor.

When you connect to the Arduino, please use a separated power for
the 7 segment display circuit. And dont forget the ground if I may
quote AWOL :)

Program by Serge J Desjardins <-- techone 
Toronto, Ontario, Canada
*/

const int led[6] = {9,10,11,12,7,8};

/*
pin 12 is MSD to pin 9 is LSD
ABCD - pin 12,11,10,9
pin 7 is the unit
pin 8 is the ten's

*/
int pin;
int counting;
int dataone;
int datatwo;
int storage;
int looping;
 
void setup()
// init the Arduino Pins
{
  for (pin =0; pin < 6; pin++ )
   {
     pinMode (led[pin], OUTPUT);
   }   
}

void loop()

{
 for (counting=0; counting<100; counting++)
 // count from 0 to 99
 {
  BCDconverter();
  for (looping=0; looping<200; looping++)
  // hold the display for 1 second
  {
    storage=dataone; // display ten's and place data to be display
    displaydigit();
    digitalWrite (led[5], LOW); // turn on tens digit
    digitalWrite (led[4], HIGH); // turn off the unit digit
    /*
    if using PNP and commmun anode, need a LOW - 0 signal to
    turn the digit on.
    if using NPN and commun cathode, need a HIGH - 1 signal to
    turn the digit on.
    so just simply change LOW to HIGH or HIGH to LOW
    */
    delay(5);   
    /*
    the time delay is to prevent "flikering" or strobe effect
    the longer the delay, the stonger the strobe effect is.
    so keep the time short.
    */
    storage=datatwo; // display unit and place data to be display
    displaydigit();
    digitalWrite (led[5], HIGH); // turn on unit digit
    digitalWrite (led[4], LOW); // turn off tens digit
    delay(5);   
  }     
 } 
 
}

void BCDconverter()
/*
extract the tens and the units numbers
*/
{
  dataone=counting/10;
  datatwo=counting % 10;
}

void displaydigit()
/*
display the data. ( see my LED display program )
And thank to AWOL for the Loop idea.
*/
{
  for (int i = 0; i < 4; i++)
  {
   digitalWrite (led[i], bitRead(storage,i));
  }

 
Logged

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1233
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just to add to the program (  multiplex 2 7 segment display ), here a schematic to connect to the Arduino

 
Logged

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