Det finns ett bibliotek till Arduino för att styra Timer1
http://playground.arduino.cc/code/timer1
Arduino - Om en kombination händer inom 2 sek
- 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
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.
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.
-
- Inlägg: 7809
- Blev medlem: 26 maj 2009, 12:20:37
- Ort: Kristinehamn
Re: Arduino - Om en kombination händer inom 2 sek
Ja det är ju en annan variant. Det exempel jag visade använder man "timeElapsed" i "#include <elapsedMillis.h>"
I det exempel du länkar till använder man "currentMillis = millis();"
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...
}
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);
}