/*
SN74HC595/6 PIN Equivalente
14 DS 14 SER SERIAL_IN
13 OE 13 OE GND
12 STCP 12 RCLK LATCH
11 SHCP 11 SRCLK CLOCK
10 MR 10 SRCLR +V
9 Q7S 9 QH SERIAL_OUT
*/
#include <ShiftRegister74HC595.h>
#define SDI 7
#define SCLK 6
#define LOAD 5
#define DIGITS 3
int button = A0;
bool flag = true;
ShiftRegister74HC595<DIGITS> sr(SDI, SCLK, LOAD);
int value, digit1, digit2, digit3;
// **************************************** Your matix
/*uint8_t digits[] = {B11000000, //0
B11111001, //1
B10100100, //2
B10110000, //3
B10011001, //4
B10010010, //5
B10000010, //6
B11111000, //7
B10000000, //8
B10010000 //9
};*/
// BCDEGFA
// **************************************** My matix
uint8_t digits[] = {B01111011, //0
B01100000, //1
B01011101, //2
B01110101, //3
B01100110, //4
B00110111, //5
B00111111, //6
B01100001, //7
B01111111, //8
B01110111 //9
};
//------------------------------------------------------------------
void setup() {
pinMode(button, INPUT_PULLUP);
}
//------------------------------------------------------------------
void loop() {
if (digitalRead(button) == LOW)
{
flag = true;
for (int i = 0; i <= 999; i++) {
if (digitalRead(button) == HIGH)
break;
showNumber(i);
delay(100);
}
}
if (digitalRead(button) == HIGH and flag == true)
{
flag = false;
delay(2000);
sr.setAllLow();
}
}
//------------------------------------------------------------------
void showNumber(int num){
digit1 = num % 10 ;
digit2 = (num / 10) % 10 ;
digit3 = (num / 100) % 10 ;
//Send them to 7 segment displays
uint8_t numberToPrint[] = {digits[digit3], digits[digit2], digits[digit1]};
sr.setAll(numberToPrint);
}