Arduino 7 - double-click

From DT^2
Revision as of 09:45, 30 July 2019 by Palo (talk | contribs) (Created page with "<syntaxhighlight lang="C++"> void setup() { pinMode(3, INPUT); Serial.begin(9600); } void loop() { if (digitalRead(3)) { while (digitalRead(3) == 1) { } delay...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
void setup() {
  pinMode(3, INPUT);
  Serial.begin(9600);
}

void loop() {
  if (digitalRead(3))
  {
    while (digitalRead(3) == 1) { }
    delay(50);
    long cas1 = millis();
    int double_click = 0;
    while (millis() < cas1 + 400) 
    {
      if (digitalRead(3) == 1)
        double_click = 1; 
    }     
    if (double_click == 1) Serial.println("double-click");
    else Serial.println("click");
    delay(200);
  }
}