Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

Arduino Ampelsteuerung

8. November 2011

3 Buttons kontrollieren 3 Lampen. Wenn eine Lampe eingeschaltet wird, erlischt der eingeschaltete Lampe. Mit dem Serial Monitor kann der Zustand kontrolliert werden.

08112011

#define LED_RED 11
#define LED_ORANGE 12
#define LED_GREEN 13

#define BUTTON_RED 5
#define BUTTON_ORANGE 6
#define BUTTON_GREEN 7

boolean rFlag = false;
boolean oFlag = false;
boolean gFlag = false;

void setup(){
  Serial.begin(9600);
  pinMode(LED_RED, OUTPUT);
  pinMode(LED_ORANGE, OUTPUT);
  pinMode(LED_GREEN, OUTPUT);

  pinMode(BUTTON_RED, INPUT);
  pinMode(BUTTON_ORANGE, INPUT);
  pinMode(BUTTON_GREEN, INPUT);

  digitalWrite(BUTTON_RED, HIGH);
  digitalWrite(BUTTON_ORANGE, HIGH);
  digitalWrite(BUTTON_GREEN, HIGH);

}
void loop(){

  if(digitalRead(BUTTON_RED) == LOW){
    if(!rFlag){
      rFlag = true;
      gFlag = false;
      oFlag = false;
      Serial.println("red");
      delay(200);
    }
    else{
      rFlag = false;
      delay(200);
    }
  }
  if(digitalRead(BUTTON_ORANGE) == LOW){
    if(!oFlag){
      oFlag = true;
      rFlag = false;
      gFlag = false;
      Serial.println("orange");
      delay(200);
    }
    else{
      oFlag = false;
      delay(200);
    }
  }
  if(digitalRead(BUTTON_GREEN) == LOW){
    if(!gFlag){
      gFlag = true;
      oFlag = false;
      rFlag = false;
      Serial.println("green");
      delay(200);
    }
    else{
      gFlag = false;

      delay(200);
    }
  }
  if(rFlag){
    digitalWrite(LED_RED, HIGH);
  }
  if(!rFlag){
    digitalWrite(LED_RED, LOW);
  }
  if(oFlag){
    digitalWrite(LED_ORANGE, HIGH);
  }
  if(!oFlag){
    digitalWrite(LED_ORANGE, LOW);
  }
  if(gFlag){
    digitalWrite(LED_GREEN, HIGH);

  }
  if(!gFlag){
    digitalWrite(LED_GREEN, LOW);

  }
}