#include "TimerOne.h"
byte value;
int laststate=HIGH;
int actstate=HIGH;
int cnt=0;
void setup() { //Pins 10-13 werden als Outputs deklariert
for (int pin=10; pin<14; pin++) {
pinMode(pin, OUTPUT);
digitalWrite(pin, HIGH);
}
pinMode(2, INPUT);
}
void setLED(int value){
for (int n=0; n<4; n++) { //Zählt Bitstellen und Pinnr. für LED
if(bitRead(value, n)) digitalWrite(n+10, LOW); //Wenn Bit an Stelle n 1 ist, schalte LED an
else digitalWrite(n+10, HIGH); //Wenn Bit an Stelle n 0 ist, schalte LED aus
}
}
void loop() {
actstate=digitalRead(2);
if (actstate==HIGH && laststate==LOW) laststate=HIGH;
if (actstate==LOW && laststate==HIGH) {
cnt++;
setLED(cnt);
laststate=LOW;
}
delay(50);
}