#define BUTTON 13
#define BUTTON_2 12
byte which_animation = 2;
byte const pinCount = 8;
byte pinsFor7seg[pinCount] = {2, 3, 4, 5, 6, 7, 8, 9}; // {A,B,C,D,E,F,G,DP}
byte numbers[23][pinCount] = {
{1, 1, 1, 1, 1, 1, 0, 0}, //0
{0, 1, 1, 0, 0, 0, 0, 0}, //1
{1, 1, 0, 1, 1, 0, 1, 0}, //2
{1, 1, 1, 1, 0, 0, 1, 0}, //3
{0, 1, 1, 0, 0, 1, 1, 0}, //4
{1, 0, 1, 1, 0, 1, 1, 0}, //5
{1, 0, 1, 1, 1, 1, 1, 0}, //6
{1, 1, 1, 0, 0, 0, 0, 0}, //7
{1, 1, 1, 1, 1, 1, 1, 0}, //8
{1, 1, 1, 1, 0, 1, 1, 0}, //9
{1, 0, 0, 1, 0, 0, 1, 0}, //error - 10
{0, 0, 0, 0, 0, 0, 0, 0}, //erase - 11
{1, 0, 0, 0, 0, 0, 0, 0}, // A - 12
{0, 1, 0, 0, 0, 0, 0, 0}, // B - 13
{0, 0, 1, 0, 0, 0, 0, 0}, // C - 14
{0, 0, 0, 1, 0, 0, 0, 0}, // D - 15
{0, 0, 0, 0, 1, 0, 0, 0}, // E - 16
{0, 0, 0, 0, 0, 1, 0, 0}, // F - 17
{0, 0, 0, 0, 0, 0, 1, 0}, // G - 18
{0, 1, 1, 0, 0, 0, 0, 1}, //1 + DP - 19
{1, 1, 0, 1, 1, 0, 1, 1}, //2 + DP - 20
{1, 1, 1, 1, 0, 0, 1, 1}, //3 + DP - 21
{0, 1, 1, 0, 0, 1, 1, 1}, //4 + DP - 22
};
void setup() {
for (byte pin : pinsFor7seg) {
pinMode(pin, OUTPUT);
}
pinMode(BUTTON, INPUT_PULLUP); //automaticke zapojení PULLUP do obvodu
pinMode(BUTTON_2, INPUT_PULLUP); //automaticke zapojení PULLUP do obvodu
showDigit(8, true); //kontrola zdali svítí vsechny segmenty
delay(1000);
}
void loop() {
if (digitalRead(BUTTON_2) == LOW) {
switch (which_animation) {
case 1:
showDigit(19, true);
which_animation = 2; // had
break;
case 2:
showDigit(20, true); // nula
which_animation = 3;
break;
case 3:
showDigit(21, true); // probliknutí
which_animation = 4;
break;
case 4:
showDigit(22, true); // animace načítání čísla
which_animation = 1;
break;
}
delay(500);
}
if (digitalRead(BUTTON) == LOW) {
int randomnumber = random(6) + 1;
switch (which_animation) {
case 1:
if (randomnumber == 1) {
subanimation_1 ();
} else if (randomnumber == 2) {
subanimation_2 ();
} else if (randomnumber == 3) {
subanimation_3 ();
} else if (randomnumber == 4) {
subanimation_4 ();
} else if (randomnumber == 5) {
subanimation_5 ();
} else if (randomnumber == 6) {
subanimation_6 ();
}
break;
case 2:
animation();
break;
case 3:
animation_2();
break;
case 4:
animation_3();
break;
}
delay(75);
showDigit(randomnumber, true);
}
}
void animation() { //animace jenž je první v cyklu
showDigit(11, true);
delay(222);
showDigit(15, true);// D - 15
delay(111);
showDigit(14, true);// C - 14
delay(111);
showDigit(18, true);// G - 18
delay(111);
showDigit(17, true);// F - 17
delay(111);
showDigit(12, true);// A - 12
delay(111);
showDigit(13, true);// B - 13
delay(111);
showDigit(18, true);// G - 18
delay(111);
showDigit(16, true);// E - 16
delay(111);
showDigit(15, true);// D - 15
}
void animation_2() { //animace jenž je druhá v cyklu
delay(250);
showDigit(15, true);// D - 15
delay(111);
showDigit(14, true);// C - 14
delay(111);
showDigit(13, true);// B - 13
delay(111);
showDigit(12, true);// A - 12
delay(111);
showDigit(17, true);// F - 17
delay(111);
showDigit(16, true);// E - 16
delay(111);
showDigit(15, true);// D - 15
}
void animation_3() {
delay(500);
showDigit(11, true);
delay(250);
}
void animation_4() {
delay(250);
showDigit(18, true);
delay(250);
}
void subanimation_1() {
delay(500);
showDigit(14, true);
delay(500);
showDigit(13, true);
delay(500);
}
void subanimation_2() {
delay(500);
showDigit(12, true);
delay(500);
showDigit(13, true);
delay(500);
showDigit(18, true);
delay(500);
showDigit(16, true);
delay(500);
showDigit(15, true);
delay(500);
}
void subanimation_3() {
delay(500);
showDigit(12, true);
delay(500);
showDigit(13, true);
delay(500);
showDigit(18, true);
delay(500);
showDigit(14, true);
delay(500);
showDigit(15, true);
delay(500);
}
void subanimation_4() {
delay(500);
showDigit(14, true);
delay(500);
showDigit(13, true);
delay(500);
showDigit(18, true);
delay(500);
showDigit(17, true);
delay(500);
}
void subanimation_5() {
delay(500);
showDigit(12, true);
delay(500);
showDigit(17, true);
delay(500);
showDigit(18, true);
delay(500);
showDigit(14, true);
delay(500);
showDigit(15, true);
delay(500);
}
void subanimation_6() {
delay(500);
showDigit(12, true);
delay(500);
showDigit(17, true);
delay(500);
showDigit(16, true);
delay(500);
showDigit(15, true);
delay(500);
showDigit(14, true);
delay(500);
showDigit(18, true);
delay(500);
}
void showDigit(byte number, bool anode) {
for (int i = 0; i < pinCount; i++) {
if (anode) digitalWrite(pinsFor7seg[i], !numbers[number][i]);
else digitalWrite(pinsFor7seg[i], numbers[number][i]);
}
}