Nonetheless it is a cheap and fast prototyping platform for any electronics enthusiast with some programming knowledge.
Recently my usual electronics shop had a stock clearance of 7 segment LCD displays, available in two digit (two dots) and four digit (three dots and clock colon). I bought two of each and went home trying to figure out how to use them.

Turns out you must drive the segments you want to lit up in AC, for that you must alternate the driving of the common and segments at a reasonable frequency.
I use a array to keep the bit patterns for the display as it makes it easier when you have to output one bit at the time.
/*
driving one 7-seg LCD display
value is incrementing every second
every 10ms display positive 10ms then negative
*/
// Data for digits 0-9 g.f.e.d.c.b.a.: 7 BITS ONLY
byte digs[] = { B0111111, B0000110, B1011011, B1001111, B1100110, B1101101, B1111101, B0000111, B1111111, B1101111 };
long previousMillis = 0; // will store last time LED was updated
long interval = 1000; // interval at which to blink (milliseconds)
byte count;
void setup() // run once, when the sketch starts
{
pinMode(9, OUTPUT); // COMMON DISP 2
pinMode(8, OUTPUT); // DISP2 Seg-G
pinMode(7, OUTPUT); // DISP2 Seg-F
pinMode(6, OUTPUT); // DISP2 Seg-E
pinMode(5, OUTPUT); // DISP2 Seg-D
pinMode(4, OUTPUT); // DISP2 Seg-C
pinMode(3, OUTPUT); // DISP2 Seg-B
pinMode(2, OUTPUT); // DISP2 Seg-A
}
void loop() // run over and over again
{
if (millis() - previousMillis > interval) {
previousMillis = millis(); // remember the last time we blinked the LED
if (++count > 9) count=0;
}
output(count,true);
delay(10);
output(count,false);
delay(10);
}
void output(byte a,boolean inv) {
byte val=digs[a];
if (inv) val = !val; // invert DC current
digitalWrite(9,bitRead(val,7)); // COMMON DSP 2
digitalWrite(8,bitRead(val,6)); // DISP2 Seg-G
digitalWrite(7,bitRead(val,5)); // DISP2 Seg-F
digitalWrite(6,bitRead(val,4)); // DISP2 Seg-E
digitalWrite(5,bitRead(val,3)); // DISP2 Seg-D
digitalWrite(4,bitRead(val,2)); // DISP2 Seg-C
digitalWrite(3,bitRead(val,1)); // DISP2 Seg-B
digitalWrite(2,bitRead(val,0)); // DISP2 Seg-A
}
2 comments:
If you want to control more than 1 digit with a bigger screen using Arduino take a look at my 7 segment LCD/LED library :)
http://code.google.com/p/arduino-seven-segment/
If you want to control more than 1 digit with a bigger screen using Arduino take a look at my 7 segment LCD/LED library :)
http://code.google.com/p/arduino-seven-segment/
Post a Comment