#include <TinyWireM.h> // To use the Adafruit's TinyWireM library:
#include <Tiny4kOLED.h>
byte buttonPins[] = {1, 3, 4};
int a = 0;
int b = 0;
int c = 0;
int ovladanecislo = 0;
int Password[] = {3, 1, 2};
void setup() {
for (int i = 0; i < 4; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);
// Two fonts are supplied with this library, FONT8X16 and FONT6X8
oled.setFont(FONT6X8);
// To clear all the memory
oled.clear();
oled.on();
splash(0);
splash(1);
splash(2);
}
void loop() {
if (digitalRead(buttonPins[0]) == LOW) {
switch (ovladanecislo) {
case 0: a = a + 1;
if (a > 9) {
a = 0;
}
break;
case 1: b = b + 1;
if (b > 9) {
b = 0;
}
break;
case 2: c = c + 1;
if (c > 9) {
c = 0;
}
break;
}
splash(1);
}
if (digitalRead(buttonPins[1]) == LOW) {
switch (ovladanecislo) {
case 0: if (a == 0) {
a = 9;
}
else {
a = a - 1;
}
break;
case 1: if (b == 0) {
b = 9;
}
else {
b--;
}
break;
case 2: if (c == 0) {
c = 9;
}
else {
c--;
}
break;
}
splash(1);
}
if (digitalRead(buttonPins[2]) == LOW) {
ovladanecislo++;
if (ovladanecislo > 2) {
/*if (a == Password[0] & b == Password[1] & c == Password[2])
{
vyhra();
}
else {
prohra();
}*/
ovladanecislo=0;
}
splash(2);
}
}
void splash(int co ) {
switch(co){
case 0:
oled.clear();
oled.setCursor(15, 1);
oled.print(F("Zadejte vstupní kód"));
break;
case 1:
oled.setCursor(35, 3);
oled.print(a);
oled.print(" - ");
oled.print(b, 1);
oled.print(" - ");
oled.print(c, 1);
break;
case 2:
switch (ovladanecislo) {
case 0: oled.setCursor(35, 2);
break;
case 1: oled.setCursor(59, 2);
break;
case 2: oled.setCursor(83, 2);
break;
}
oled.print("_");
}
}
void vyhra() {
oled.clear();
oled.setCursor(15, 1);
oled.print(F("Uhodli jste heslo"));
oled.setCursor(15, 3);
oled.print("kod je : 1234");
ovladanecislo = 0;
delay(1000);
}
void prohra() {
oled.clear();
oled.setCursor(15, 1);
oled.print(F("Nespravne Heslo"));
oled.setCursor(15, 3);
oled.print("Skuste to znovu");
a = 0;
b = 0;
c = 0;
ovladanecislo = 0;
}