//**************************************************************//
// Name : shiftOutCode, Predefined Dual Array Style //
// Author : Carlyn Maw, Tom Igoe //
// Date : 25 Oct, 2006 //
// Version : 1.0 //
// Notes : Code for using a 74HC595 Shift Register //
// : to count from 0 to 255 //
//****************************************************************
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
//Pin connected to button
const uint8_t buttonPin = 2;
//button state
int buttontState;
void setup() {
//set OUTPUT
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
}
const uint8_t digitTable[] = { //digits table
0b11000000,
0b11111001,
0b10100100,
0b10110000,
0b10011001,
0b10010010,
0b10000010,
0b11111000,
0b10000000,
0b10010000,
};
int dec_min = 0;
int one_min = 0;
int dec_sec = 0;
int one_sec = 0;
int counter = 0;
void sendScore(uint8_t d_min, uint8_t n_min, uint8_t d_sec, uint8_t n_sec) {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, n_sec);
shiftOut(dataPin, clockPin, MSBFIRST, d_sec);
shiftOut(dataPin, clockPin, MSBFIRST, n_min);
shiftOut(dataPin, clockPin, MSBFIRST, d_min);
digitalWrite(latchPin, HIGH);
}
void loop() {
counter = counter+10;
if (counter>100) {one_sec++; counter = 0;}
if (one_sec>9) {dec_sec++; one_sec = 0;}
if (dec_sec>5) {one_min++; dec_sec = 0;}
if (one_min>9) {dec_min++; one_min = 0;}
if (dec_min>5) {dec_min = 0;}
sendScore(digitTable[dec_min],digitTable[one_min],digitTable[dec_sec],digitTable[one_sec]);
buttontState = digitalRead(buttonPin);
Serial.println(buttontState);
if (buttontState == 0) {
dec_min = 0;
one_min = 0;
dec_sec = 0;
one_sec = 0;
counter = 0;
}
delay(100);
// Защёлка передача
}