/* Led-Binärzähler
   Autor: Maximilian LEchner 
   Klasse: 3AHETS
 
Mithilfe von zwei Pushbuttons wird binär rauf oder 
  runter gezählt
 

 */
#define LedPin1 5
#define LedPin2 4
#define LedPin3 3
#define LedPin4 2
#define ButtonPin1 13
#define ButtonPin2 12
#define NumberOfLeds 4
int const timer = 200;
 
unsigned long previousMillis;
 
bool ButtonState1;
bool ButtonState2;
int counter = 0;
 
void setup() {
  pinMode(LedPin1, OUTPUT);
  pinMode(LedPin2, OUTPUT);
  pinMode(LedPin3, OUTPUT);
  pinMode(LedPin4, OUTPUT);
  pinMode(13, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  Serial.begin(9600);
}
 
void loop() {
  ButtonState1 = !digitalRead(ButtonPin1);
  ButtonState2 = !digitalRead(ButtonPin2);
 
  if (millis() - previousMillis >= timer){
    counter = counter + ButtonState1;
    counter = counter - ButtonState2;
    previousMillis = millis();
  }
 
  if(counter >= pow(2,NumberOfLeds)){
    counter = 15;
  }
  else if(counter <= 0){
    counter = 0;
  }
 
  digitalWrite(LedPin4, (counter & B0001) == B0001);
  digitalWrite(LedPin3, (counter & B0010) == B0010);
  digitalWrite(LedPin2, (counter & B0100) == B0100);
  digitalWrite(LedPin1, (counter & B1000) == B1000);

  int status1 = digitalRead(2);
  int status2 = digitalRead(3);
  int status3 = digitalRead(4);
  int status4 = digitalRead(5);
  //Serial Monitor Ausgabe:
  Serial.println(status1);
  Serial.println(status2);
  Serial.println(status3);
  Serial.println(status4);

}