-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch_pulldown.ino
52 lines (48 loc) · 1.13 KB
/
sketch_pulldown.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <Keyboard.h>
const int tlacidloVpred = 2;
int tlacidloStav;
int poslednetlacidloStav = LOW;
unsigned long poslednezakmitCas = 0;
unsigned long zakmitDelay = 50;
int pocitadlo = 0;
const int tlacidloVlavo = 3;
const int tlacidloVpravo = 4;
void setup() {
Keyboard.begin();
Serial.begin(115200);
pinMode(tlacidloVpred, INPUT);
pinMode(tlacidloVlavo, INPUT);
pinMode(tlacidloVpravo, INPUT);
}
void loop() {
int citanie = digitalRead(tlacidloVpred);
while(digitalRead(tlacidloVlavo)){
Keyboard.press('a');
delay(300);
Keyboard.releaseAll();
}
while(digitalRead(tlacidloVpravo)){
Keyboard.press('d');
delay(300);
Keyboard.releaseAll();
}
if (citanie != poslednetlacidloStav) {
poslednezakmitCas = millis();
}
if ((millis() - poslednezakmitCas) > zakmitDelay) {
if (citanie != tlacidloStav) {
tlacidloStav = citanie;
if (tlacidloStav == HIGH) {
pocitadlo++;
}
}
}
poslednetlacidloStav = citanie;
Serial.println("Hodnota counteru:");
Serial.println(pocitadlo);
if(pocitadlo>=5){
Keyboard.write(218);
pocitadlo = 0;
Serial.println("Pohyb vpred");
}
}