Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleLösung Aufgabe 3
collapsetrue
#define BUTTON  2
#define LED_ONE 13
 
int buttonState [40];
long buttonTime [40];
int lastButtonState = HIGH;
 
long lastTimePressed = 0;
int timeOutDelay = 2000;
int counter = 0;
 
boolean replay = false;
int sequenceLenght = 0;
 
void setup()
{
  pinMode(BUTTON, INPUT);
  digitalWrite(BUTTON, HIGH);
  pinMode(LED_ONE, OUTPUT);
}
 
void loop()
{
  int reading = digitalRead(BUTTON);
 
  if(reading != lastButtonState)
  {
    replay = false;
    buttonState[counter] = reading;
    buttonTime[counter] = millis();
    lastTimePressed = millis();
    lastButtonState = reading;
    counter++;
  }
   
  if((millis() - lastTimePressed) > timeOutDelay)
  {
    sequenceLenght = counter;
    counter = 0;
    replay = true;
  }
   
  if(replay == true)
  {
    for(int i=0; i<sequenceLenght-1; i++)
    {
      digitalWrite(LED_ONE, !buttonState[i]);
      delay(buttonTime[i+1]-buttonTime[i]);
    }
    replay = false;
    digitalWrite(LED_ONE, LOW);
  }
}

Weitere Informationen

Arduino: DigitalPins - Referenz auf Arduino.cc
Tom Igoe: Digital Input & Output - Tom Igoe