#include <LiquidCrystal.h>
bool test = true;
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
int randnum = 0;
int pozicia = 0;
void setup() {
// put your setup code here, to run once:
lcd.begin(16, 2);
DDRD |= 1<<2;
DDRD |= 1<<3;
DDRB &= ~(1<<5);
PORTB |= (1<<5);
randomSeed(analogRead(A0));
}
//nove cislo - aktualny krok
void loop() {
// put your main code here, to run repeatedly:
if ( (PINB&(1<<5)) == 0 && test == true)
{
PORTD &= ~(1<<2);
randnum = random(0, 59);
PORTB |= 1<<0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(randnum);
test = false;
}
while(rnd > pozicia)
{
krok('r');
pozicia++;
}
while(rnd < pozicia)
{
krok('l');
pozicia--;
}
else if ( (PINB&(1<<5)) != 0 && test != true)
{
test = true;
}
}
void krok(char smer)
{
if(smer == 'r')
PORTB |= 1<<0;
else
PORTB &= ~(1<<0);
PORTB |= 1<<1;
delay(1);
PORTB &= ~(1<<1);
delay(1);
}