Arduino - tlačidlá

From DT^2
Revision as of 10:10, 31 July 2018 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Vyskúšajme zobrazovať stav tlačidla na sériovom porte:

1 void setup() {
2   Serial.begin(9600);
3   pinMode(12, INPUT);
4   digitalWrite(12, HIGH);
5 }
6 void loop() {
7   Serial.println(digitalRead(12));
8   delay(500);
9 }

Počítadlo ráta koľkokrát sa stlačidlo tlačidlo:

 1 int i;
 2 void setup() {
 3   Serial.begin(9600);
 4   pinMode(12, INPUT);
 5   digitalWrite(12, HIGH);
 6   i = 0;
 7 }
 8 void loop() {
 9   Serial.println(i);
10   delay(500);
11   if (digitalRead(12) == 0)
12   {  
13     i++;
14     delay(50); // debounce
15     while (digitalRead(12) == 0) {} 
16   }
17 }