Arduino - Om en kombination händer inom 2 sek

C, C++, Pascal, Assembly, Raspberry, Java, Matlab, Python, BASIC, SQL, PHP, etc.
Användarvisningsbild
morten.dynamite
Inlägg: 62
Blev medlem: 9 juni 2012, 19:30:30
Ort: Charlottenberg

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

Inlägg av morten.dynamite »

Det finns ett bibliotek till Arduino för att styra Timer1

http://playground.arduino.cc/code/timer1
Skogen
Inlägg: 903
Blev medlem: 5 januari 2013, 22:50:34
Ort: Alingsås

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

Inlägg 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.
SeniorLemuren
Inlägg: 7807
Blev medlem: 26 maj 2009, 12:20:37
Ort: Kristinehamn

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

Inlägg 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);
  }
Skriv svar