const int clockPin = 4;
const int latchPin = 3;
const int dataPin = 2;
uint16_t cislo = 0;
unsigned long previousMillis = 0;
const int cifry[]= {
0b00000011,//0
0b10011111,//1
0b00100101,//2
0b00001101,//3
0b10011001,//4
0b01001001,//5
0b01000001,//6
0b00011111, //7
0b00000001,//8
0b00001001,//9
0b11111111, //-
};
uint8_t segment[] = {1, 2, 4, 8,};
void setup() {
// put your setup code here, to run once:
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long currentMillis= millis();
if(currentMillis - previousMillis >=300){
previousMillis=currentMillis;
cislo = (cislo + 1)%10000;
}
zobrazCislo(cislo);
}
void zobrazCislo(int cislo)
{
for(int i=0; i<4; i++)
{
uint8_t cifra = cislo%10;
cislo /= 10;
digitalWrite(latchPin, LOW);
shiftOut(dataPin,clockPin,LSBFIRST,cifry[cifra]);
shiftOut(dataPin,clockPin,MSBFIRST,segment[i]);
digitalWrite(latchPin, HIGH);
}
}