Difference between revisions of "Arduino 15 - tripple-click"
(Created page with "<syntaxhighlight lang="C++"> void setup() { pinMode(4, INPUT); Serial.begin(9600); } int dotyk() { long neskoro = millis() + 500; int pocet = 0; int hodnota = digit...") |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
int dotyk() | int dotyk() | ||
{ | { | ||
+ | while (digitalRead(4) == 0) { } | ||
long neskoro = millis() + 500; | long neskoro = millis() + 500; | ||
int pocet = 0; | int pocet = 0; | ||
Line 15: | Line 16: | ||
pocet++; | pocet++; | ||
hodnota = digitalRead(4); | hodnota = digitalRead(4); | ||
− | delay( | + | delay(20); |
} | } | ||
} | } | ||
− | return pocet / 2; | + | return (pocet + 1)/ 2; |
} | } | ||
Latest revision as of 12:34, 6 August 2019
void setup() {
pinMode(4, INPUT);
Serial.begin(9600);
}
int dotyk()
{
while (digitalRead(4) == 0) { }
long neskoro = millis() + 500;
int pocet = 0;
int hodnota = digitalRead(4);
while (millis() < neskoro) {
if (digitalRead(4) != hodnota)
{
pocet++;
hodnota = digitalRead(4);
delay(20);
}
}
return (pocet + 1)/ 2;
}
void loop() {
Serial.println(dotyk());
}