int nahodaCas = 0;
int zacatek;
int konec;
int konecnyCas;
int body = 0;
void setup() {
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
pinMode(3, OUTPUT);
}
void loop() {
if(nahodaCas == 0) {
digitalWrite(3, LOW);
GeneratorNahody(); //Generuje náhodný delay na zapnutí LED
delay(nahodaCas / 2);
GeneratorNahody();
digitalWrite(3, HIGH);
zacatek = millis(); //Začne počítat čas
}
if(digitalRead(2) == LOW) {
konec = millis();
konecnyCas = konec - zacatek;
body = body + (10000 / konecnyCas);
Serial.println(String(konecnyCas) + "ms");
nahodaCas = 0;
}
else {
nahodaCas--;
delay(1);
}
}
void GeneratorNahody () {
nahodaCas = random(2000, 5001);
}