First of all. Yes I am aware of the thousands of threads about flickering issues with registers but my problem is different or at least nothing I tried worked yet. I have a common annode 2 digit display which uses 10 pins and a seperate annode for each digit so I have to switch between the digits all the time. I am using 1 74HC595 Shift Register and atm for testing I have set the code to only update the display every second.
The problem I have is that 1 digit flashes for like the blink of an eye very dim, than 1 second later the other digit does the same. I have tested the display and it worked so it is fine.
Thanks in advance for any help!
#define DIGIT_1_PIN 4
#define DIGIT_2_PIN 5
#define CLOCK_PIN 7
#define LATCH_PIN 8
#define DATA_PIN 9
#define DISPLAY_REFRESH_RATE 1000
#define DISPLAY_TIMEOUT_MS 5000
int numbers[10] = {
0b10000001,
0b11001111,
0b01101101,
0b10000110,
0b11001100,
0b10100100,
0b10100000,
0b10001111,
0b10000000,
0b10000100,
};
int set_humidity = 50;
bool display_on = false;
int current_digit = 2;
unsigned long display_last_refresh = 0;
void refreshDisplay(int value, bool on) {
int digit = 0;
digitalWrite(LATCH_PIN, LOW);
digit = numbers[value];
if (!on) {
digitalWrite(DIGIT_1_PIN, LOW);
digitalWrite(DIGIT_2_PIN, LOW);
}
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, digit);
digitalWrite(LATCH_PIN, HIGH);
}
void setup() {
pinMode(DIGIT_1_PIN, OUTPUT);
pinMode(DIGIT_2_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
pinMode(DATA_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
set_humidity = changing value;
if (millis() > display_last_refresh + DISPLAY_REFRESH_RATE) {
int value = 0;
if (current_digit == 1) {
current_digit = 2;
value = set_humidity % 10;
digitalWrite(DIGIT_1_PIN, LOW);
digitalWrite(DIGIT_2_PIN, HIGH);
} else {
current_digit = 1;
value = set_humidity / 10;
digitalWrite(DIGIT_1_PIN, HIGH);
digitalWrite(DIGIT_2_PIN, LOW);
}
refreshDisplay(value, display_on);
display_last_refresh = millis();
Serial.println("Refreshed Display");
}
}