So i bought a 6 digit 16 segment display common anode, and i managed to get the a clock working with 1 TLC5940 for the cathodes and 6 arduino pins for the anodes.
My problem here is that in the first digit appear the ones of the seconds, the second digit the tens of the hour, the third digit the ones of the hour, and so on.
I dont know what the problem is with the code, so if anyone could help me...
My schematic is like those found in the net
#include "Tlc5940.h"
#include <Wire.h>
#include "RTClib.h"
RTC_DS3231 rtc;
int digitpins[6] = {7, 6, 5, 4, 2, 8};
int tempo[6];
int numeros[36][16] = {
/*a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p*/
{1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0}, // 0{B00000000, B01101111}
{1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0}, // 1{B11001111, B11111111}
{1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1}, // 2{B00010001, B11011011}
{1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1}, // 3{B00000011, B11011011}
{0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1}, // 4{B11001110, B11011011}
{1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1}, // 5{B00100010, B11011011}
{1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1}, // 6{B00100000, B11011011}
{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0}, // 7{B00111111, B10110111}
{1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1}, // 8{B00000000, B11011011}
{1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1}, // 9{B00000010, B11011011}
{1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1}, // A
{1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0}, // B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0, 0, 0, 1, 0}, // V
{0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0}, // W
{0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0}, // X
{0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1}, // Y
{1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0}, // Z
};
void setup() {
Tlc.init();
//----------------------------
#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));
}
//----------------------------
for (int i = 0; i < 6; i++) {
pinMode(digitpins[i], OUTPUT);
digitalWrite(digitpins[i], LOW);
}
}
////------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void loop() {
for (int i = 0; i < 6; i++) {
gettime();
for (int j = 0; j < 16; j++) {
if (numeros[tempo[i]][j] == 1) {
Tlc.set(j, 4095);
}
else {
Tlc.set(j, 0);
}
}
digitalWrite(digitpins[i], HIGH);
delay(1);
Tlc.update();
digitalWrite(digitpins[i], LOW);
Tlc.clear();
}
}
////------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void gettime() {
DateTime now = rtc.now();
tempo[0] = (now.hour() / 10) % 10;
tempo[1] = now.hour() % 10;
tempo[2] = (now.minute() / 10) % 10;
tempo[3] = now.minute() % 10;
tempo[4] = (now.second() / 10) % 10;
tempo[5] = now.second() % 10;
}