Difference between revisions of "Arduino - tlačidlá"

From DT^2
Jump to: navigation, search
(Created page with "Vyskúšajme zobrazovať stav tlačidla na sériovom porte: <syntaxhighlight lang="C" line='line'> void setup() { Serial.begin(9600); pinMode(12, INPUT); digitalWrite(1...")
 
 
(2 intermediate revisions by the same user not shown)
Line 10: Line 10:
 
   Serial.println(digitalRead(12));
 
   Serial.println(digitalRead(12));
 
   delay(500);
 
   delay(500);
 +
}
 +
</syntaxhighlight>
 +
 +
Počítadlo ráta koľkokrát sa stlačidlo tlačidlo:
 +
 +
<syntaxhighlight lang="C" line='line'>
 +
int i;
 +
void setup() {
 +
  Serial.begin(9600);
 +
  pinMode(12, INPUT);
 +
  digitalWrite(12, HIGH);
 +
  i = 0;
 +
}
 +
void loop() {
 +
  Serial.println(i);
 +
  delay(500);
 +
  if (digitalRead(12) == 0)
 +
  { 
 +
    i++;
 +
    delay(50); // debounce
 +
    while (digitalRead(12) == 0) {}
 +
  }
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 08:10, 31 July 2018

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 }