Go Down

Topic: Arduino +Sparkfuns 4-digit 7-segment 16pin display (Read 26 times) previous topic - next topic

cjands40

I've used the STLED316S LED driver in several projects with good results.  It's inexpensive and can drive up to 6 common anode digits plus 8 additional discrete LEDs with brightness control.  It can also read from up to 16 tactile switches.  I'm currently developing an alarm clock shield using this chip - I hope to post details soon.  I've written a library for the chip I plan to share.  It's only available in an SMT package but you could always put one on a breakout board if that's a problem.

GmDude66

Can anyone please help me get hari's code working with my 4 digit 7 segment display?

It is almost the same as sparkfun's except the pins are in a different configuration.

Here is the pin configuration:
1-8 on bottom (left to right)
9-16 on top (right to left)




Thanks!


hari

Pinout is not the only difference.  Your display is common Cathode and my SparkFun display is common Anode.  So basically wherever the code sets pin to HIGH it needs to set it LOW and vice versa.  I only had to make 4 changes to the code and I've highlighted them [glow]yellow[/glow].  That should work.  Good luck!

Code: [Select]
/*
 WAS: Testing SparkFun's 4-digit 7-Segment Display (Blue)
 NOW: Altered for GmDude66 for H.LTC.4727
*/

int segmentA = 0; // Segments A thru P == pins 0 thru 7
int digit0 = 10; // Digits 3 thru 0 == pins 10 thru 13 (0 is LEFT most digit)

/*
[glow]Change#1 Added wiring guide for your H.LTC.4727[/glow]

W I R I N G   G U I D E

=== Common Cathode digits ===
Arduino  Display  Digit
 10        1       0 Leftmost
 11        2       1
 12        6       2
 13        8       3 Rightmost
 
=== Anode Segments ===
Arduino  Display   Segment
  0       14         A
  1       16         B
  2       13         C
  3       3          D
  4       5          E
  5       11         F
  6       15         G
*/

/*
10 digits:
Each defines which segments should be on/off for that digit: A,B,C,D,E,F,G,P
*/
byte numbers[10] =
{
 B11000000, // 0
 B11111001, // 1
 B10100100, // 2
 B10110000, // 3
 B10011001, // 4
 B10010010, // 5
 B10000010, // 6
 B11111000, // 7
 B10000000, // 8
 B10010000  // 9
};

void setup()
{
 for (byte segment = 0; segment < 8; segment++)
   pinMode(segmentA+segment,OUTPUT);

 for (byte digit = 0; digit < 4; digit++)
   pinMode(digit0+digit,OUTPUT);
}

int perDigitTime = 100;
int digitPosition = 1;  // Start anywhere but zero so we won't crash when we try to turn off previous digit.
unsigned long previousMillis = 0;

int value = 0;
int powerOfTen[] = {
 1,10,100,1000};

void RefreshDisplay()
{
[glow]  //Change#2 (Your display is common Cathode, so to turn OFF a digit, we need to set it to +5)[/glow]
 digitalWrite(digit0 + digitPosition, [glow]HIGH[/glow]);  // Turn off previous digit

 digitPosition++;
 if (digitPosition > 3) digitPosition = 0;

 int digitValue = value % powerOfTen[ digitPosition+1 ] / powerOfTen[digitPosition];
 int number =  numbers[ digitValue ];
 
 if ((number > 0) || (value < powerOfTen[ digitPosition+1 ]))
 {
 for (byte seg = 0; seg < 8; seg++)
   digitalWrite(segmentA+seg, [glow]1 - [/glow]bitRead(number, seg) ); [glow]// Change#3 added "1-" to invert the bit for your common Cathode display[/glow]

 digitalWrite(digit0 + digitPosition, [glow]LOW[/glow]);  [glow]//Change#4 LOW will turn this digit on.[/glow]
 delay(4);
 }
}

void loop()
{
 unsigned long currentMillis = millis();
 if (currentMillis - previousMillis > perDigitTime)
 {
   previousMillis = currentMillis;
   value++;
 }

 RefreshDisplay();
}



GmDude66

#19
Mar 27, 2010, 02:11 am Last Edit: Mar 27, 2010, 03:00 am by GmDude66 Reason: 1
Thank you!

The display works perfectly now!

One more question: how would I go about getting the colon to stay lit all the time?

EDIT: Just combined your code along with ninjamastr's code to get this display working with my 74HC595

Go Up