// === 12-Minute Countdown Timer using TPIC6B595 and Common Anode 7-Segment Displays ===
/*
CONECTIONS (Q0,Q1,Q2,Q3,Q4,Q5,Q6,Q7)
|7|
|6| |5|
|4|
|2| |3|
|1| |0|
*/
#define DATA_PIN 11 //DS
#define LATCH_PIN 12 //STPC
#define CLOCK_PIN 13 //SHCP
//#define outputEnablePin 3 //OE
// (Q0,Q1,Q2,Q3,Q4,Q5,Q6,Q7)
// Segment bit mapping (a,b,c,d,e,f,g,dp) //POS (7,6,5,4,3,2,1,DP)
const byte digits[10] = {
//0b76543210
0b11101110, //0
0b00101000, //1
0b10110110, //2
0b10111010, //3
0b01111000, //4
0b11011010, //5
0b11011110, //6
0b10101000, //7
0b11111110, //8
0b11111010 //9
};
void setup() {
// Set the three SPI pins to be outputs:
pinMode(DATA_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
//pinMode(outputEnablePin, OUTPUT);
digitalWrite(LATCH_PIN, LOW);
}
void loop(){
Test_display();
}
void SalidaDatos(int dato) {
// enviamos el dato
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, dato);
// emitimos un pulso para que pase
// al registro de salida y lo podamos ver
digitalWrite(LATCH_PIN,HIGH); // pulso ALTO
digitalWrite(LATCH_PIN,LOW); // pulso BAJO
}
void Test_display(){
for(int i = 0; i<10;i++){
SalidaDatos(digits[i]);
delay(3000); // esperamos para ver el dato
}
}
/*
const byte digits[10] = {
0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
0b01100110, // 4
0b01101101, // 5
0b01111101, // 6
0b00000111, // 7
0b01111111, // 8
0b01101111 // 9
};
// Optional colon pattern (if your display supports it)
// const byte colonPattern = 0b11111111; // adjust if colon is separate
unsigned long previousMillis = 0;
int countdownSeconds = 12 * 60; // 12 minutes in seconds
void setup() {
// Set the three SPI pins to be outputs:
pinMode(DATA_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
}
void loop() {
static unsigned long lastUpdate = 0;
if (millis() - lastUpdate >= 1000 && countdownSeconds >= 0) {
lastUpdate = millis();
int minutes = countdownSeconds / 60;
int seconds = countdownSeconds % 60;
displayTime(minutes, seconds);
countdownSeconds--;
}
// When timer ends
if (countdownSeconds < 0) {
displayOff();
delay(500);
displayTime(0, 0);
delay(500);
}
}
void displayTime(int minutes, int seconds) {
byte displayData[4];
displayData[3] = digits[seconds % 10];
displayData[2] = digits[(seconds / 10) % 10];
displayData[1] = digits[minutes % 10];
displayData[0] = digits[(minutes / 10) % 10];
digitalWrite(LATCH_PIN, LOW);
for (int i = 3; i >= 0; i--) { // send MSB first (D3 → D0)
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, displayData[i]);
}
digitalWrite(LATCH_PIN, HIGH);
}
void displayOff() {
digitalWrite(LATCH_PIN, LOW);
for (int i = 0; i < 4; i++) {
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, 0xFF); // all segments off
}
digitalWrite(LATCH_PIN, HIGH);
}
*/