Difference between revisions of "Arduino 15 - tripple-click"

From DT^2
Jump to: navigation, search
(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...")
 
m
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;

Revision as of 14:32, 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(50); 
    }
  }
  return pocet / 2;
}

void loop() {
  Serial.println(dotyk());
}