Sida 2 av 2

Re: Arduino - Om en kombination händer inom 2 sek

Postat: 9 januari 2019, 12:28:23
av morten.dynamite
Det finns ett bibliotek till Arduino för att styra Timer1

http://playground.arduino.cc/code/timer1

Re: Arduino - Om en kombination händer inom 2 sek

Postat: 9 januari 2019, 20:25:46
av Skogen
Under "Fil-Exempel-02.Digital-BlinkWithoutDelay" i Arduino kan du se ett exempel på
hur man kan använda millisekunder i stället för Delay och annat.
Just det exemplet löser kanske inte ditt problem direkt men fattar du principen
så fixar du det lätt.

Re: Arduino - Om en kombination händer inom 2 sek

Postat: 9 januari 2019, 21:05:22
av SeniorLemuren
Ja det är ju en annan variant. Det exempel jag visade använder man "timeElapsed" i "#include <elapsedMillis.h>"

Kod: Markera allt

]if (timeElapsed > interval) 
  {				
      ledState = !ledState;         // toggle the state from HIGH to LOW to HIGH to LOW ... 
      digitalWrite(led, ledState);
      timeElapsed = 0;              // reset the counter to 0 so the counting starts over...
  }
I det exempel du länkar till använder man "currentMillis = millis();"

Kod: Markera allt

if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }