I am a novice Arduino programmer and am currently having trouble with a SH5461AS 4-digit/7-segment LED when using it with an Arduino Uno. I have struggled to find an accurate datasheet/tutorial of any kind for this particular model (It is the LED without the colons in between digits 2 and 3) but I believe I have it figured out.
I currently have it going through a HC595 shift register but when I removed the register and connected the LED directly to the board the problem remained. My code below is with the shift register; I am displaying it this way because it is simpler to view and I thought it would make it easier to debug.
I can display a single digit at a time correctly. However, when I try to display 2+ digits at one time, they are in the incorrect order. For example, I can count 1-9 on the first digit, then 1-9 on the 2nd digit, and so on and everything displays correctly (other digits are off). But as soon as I try to display multiple digits they are in the wrong order. So if I try to display 12__ with the last 2 digits off, 21__ is displayed with the last two digits off. If I try to display 23, 32 is displayed. If I try to display 1234, 4123 is displayed.
I am at a loss because the code seems like it should be simple.
const int DATA = 0;
const int LATCH = 1;
const int CLOCK = 2;
const int DIGIT_ONE = 3;
const int DIGIT_TWO = 4;
const int DIGIT_THREE = 5;
const int DIGIT_FOUR = 6;
//digits[0-9] corresponds to the patterns for numbers 0 -> 9.
//Add 1 to the digits[X] to turn on the dot.
byte digits[] = {B11111100, B00011000, B01101110, B00111110, B10011010, B10110110, B11110010, B00011100, B11111110, B10111110};
void setup() {
pinMode(DATA, OUTPUT);
pinMode(CLOCK, OUTPUT);
pinMode(LATCH, OUTPUT);
pinMode(DIGIT_ONE, OUTPUT);
pinMode(DIGIT_TWO, OUTPUT);
pinMode(DIGIT_THREE, OUTPUT);
pinMode(DIGIT_FOUR, OUTPUT);
digitalWrite(DIGIT_ONE, HIGH);
digitalWrite(DIGIT_TWO, HIGH);
digitalWrite(DIGIT_THREE, HIGH);
digitalWrite(DIGIT_FOUR, HIGH);
}
void loop() {
writeDigit(DIGIT_TWO, 2);
writeDigit(DIGIT_THREE, 3);
}
/*
* Write a digit to the 4-digit 7-segment LED
* - digitPin corresponding to the pin on the LED to light up the correct digit.
* - number 0-9 to display on the LED
*/
void writeDigit(int digitPin, int number) {
digitalWrite(digitPin, LOW);
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLOCK, LSBFIRST, digits[number]);
digitalWrite(LATCH, HIGH);
digitalWrite(digitPin, HIGH);
}
So in this instance, I am expecting 23 but 32 is displaying instead.
I am also having trouble with some bleeding (I don't know what the correct term is) where some segments are very faintly glowing even though I am not doing it intentionally. This is a much smaller issue, however, than digits randomly in the wrong order.
If it would help, I can try to post the circuit diagram as well.