25. September 2012
int leds[] = {8, 9, 10, 11, 12, 13}; int ledCount = 6; int btn1 = 6; int btn2 = 7; int btnCount = 0; boolean buttonState1 = false; boolean buttonState2 = false; long debounceDelay = 110; long lastDebounceTime = 0; void setup() { for(int i=0; i<ledCount; i++){ pinMode(leds[i], OUTPUT); } pinMode(btn1, INPUT); pinMode(btn2, INPUT); Serial.begin(9600); //Serial.println(sizeof(leds)); } void loop() { if(digitalRead(btn1) == LOW && (millis()-lastDebounceTime)>debounceDelay && buttonState1 == false){ Serial.println("btn 1"); lastDebounceTime = millis(); buttonState1 = true; if(btnCount<ledCount){ btnCount++; }else{ btnCount = 0; } lightCount(btnCount); Serial.println(btnCount); } if(digitalRead(btn2) == LOW && (millis()-lastDebounceTime)>debounceDelay && buttonState2 == false){ Serial.println("btn 2"); lastDebounceTime = millis(); buttonState2 = true; if(btnCount>0){ btnCount--; }else{ btnCount = ledCount; } lightCount(btnCount); Serial.println(btnCount); } if(digitalRead(btn1) == HIGH){ buttonState1 = false; // buttonState auf false setzen } if(digitalRead(btn2) == HIGH){ buttonState2 = false; } } void lightCount(int count) { for(int i=0; i<ledCount; i++){ if(i<count){ digitalWrite(leds[i], HIGH); }else{ digitalWrite(leds[i], LOW); } } }