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

From DT^2
Jump to: navigation, search
m
Line 16: Line 16:
 
       pocet++;
 
       pocet++;
 
       hodnota = digitalRead(4);
 
       hodnota = digitalRead(4);
       delay(50);  
+
       delay(20);  
 
     }
 
     }
 
   }
 
   }

Revision as of 14:33, 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 / 2;
}

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