#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
int cislo, strana = 0;
bool test = true;
bool test1 = true;
int i = 0;
void setup() {
DDRC &= ~(1<<0);
DDRD |= 0b00001100; //aj 0 aj 1 ako vystup
lcd.begin(16,2);
PORTC |= 1<<0; //pull up tlacidlo vpravo
randomSeed(analogRead(A0));
Serial.begin(9600);
krok('r');
krok('r') ;
}
void loop() {
if((PINC& (1<<0)) == 0 && test == true){
strana = cislo;
cislo = random(0,60);
lcd.setCursor(0,0);
lcd.print(cislo);
if(strana < cislo){
for(int i = 0; i < cislo - strana ; i++){
krok('r');
}
}
if(strana > cislo){
for(int i = 0; i< strana - cislo; i++){
krok('l');
}
}
test = false;
}
if((PINC& (1<<0)) != 0 && test == false){
test = true;
}
}
void krok(char smer){
if(smer == 'r')
{
PORTD |= 1<<2;
PORTD |= 1<<3;
delay(200);
PORTD &= ~(1<<3);
}
else if(smer == 'l'){
PORTD &= ~(1<<2);
PORTD |= 1<<3;
delay(200);
PORTD &= ~(1<<3);
}
}