I bought a common anode 6 digit 16 segment display, and i wanted to make a clock with it. I managed to get this to work with 2 74hc595 shift register and 2 uln2803, but i'm experiencing led ghosting and i dont know if its my code, or the circuit that needs to be improved.
I hope someone here can help me.
Similar display: display
The shifter.h library is from here: shifter
The code is similar to these: code
#include <Wire.h>
#include "RTClib.h"
RTC_DS3231 rtc;
#include <Shifter.h>
#define SER_Pin 11 //SER_IN
#define RCLK_Pin 8 //L_CLOCK
#define SRCLK_Pin 12 //CLOCK
#define NUM_REGISTERS 2
Shifter shifter(SER_Pin, RCLK_Pin, SRCLK_Pin, NUM_REGISTERS);
const static byte numeros[10][16] = {
//a,b,c,d,e,f,g,h,j,k,l,m,n,o,p,q
{1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0}, // 0
{1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0}, // 1
{1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1}, // 2
{1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1}, // 3
{0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1}, // 4
{1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1}, // 5
{1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1}, // 6
{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0}, // 7
{1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1}, // 8
{1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1}, // 9
};
//* - - a b
//* |\|/| h i j k c
//* - - p l
//* |/|\| g o n m d
//* - - f e
int digito1 = 7;
int digito2 = 6;
int digito3 = 5;
int digito4 = 4;
int digito5 = 3;
int digito6 = 2;
void setup() {
#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero
#endif
Serial.begin(9600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, lets set the time!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
pinMode(digito1, OUTPUT);
pinMode(digito2, OUTPUT);
pinMode(digito3, OUTPUT);
pinMode(digito4, OUTPUT);
pinMode(digito5, OUTPUT);
pinMode(digito6, OUTPUT);
}
void loop() {
DateTime now = rtc.now();
int su = now.second() - (int(now.second() / 10) * 10);
int sd = int(now.second() / 10); sd = sd - (int(sd / 10) * 10);
int mu = now.minute() - (int(now.minute() / 10) * 10);
int md = int(now.minute() / 10); md = md - (int(md / 10) * 10);
int hu = now.hour() - (int(now.hour() / 10) * 10);
int hd = int(now.hour() / 10); hd = hd - (int(hd / 10) * 10);
for (int j = 0; j < 16; j++) {
shifter.setPin(j, HIGH);
shifter.write();
digitalWrite(digito1, numeros[hd][j]);
digitalWrite(digito2, numeros[hu][j]);
digitalWrite(digito3, numeros[md][j]);
digitalWrite(digito4, numeros[mu][j]);
digitalWrite(digito5, numeros[sd][j]);
digitalWrite(digito6, numeros[su][j]);
//delay(1);
shifter.clear();
shifter.write();
}
}