Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.4 kB
3
Indexable
Never
#define ORANGE_LED 3
#define GREEN_LED 4
#define RED_LED 5
#define BUTTON 2

enum mode{
  DAY,
  NIGHT
};

void setup()
{
  Serial.begin(9600);
  pinMode(ORANGE_LED, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);
  pinMode(RED_LED, OUTPUT);
  pinMode(BUTTON, INPUT);
  
  Serial.println("TEST");
}

void night_mode()
{
  digitalWrite(ORANGE_LED, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  digitalWrite(ORANGE_LED, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
}

void day_mode()
{
  //red only
  digitalWrite(RED_LED, HIGH);
  digitalWrite(GREEN_LED, LOW);
  digitalWrite(ORANGE_LED, LOW);
  
  //orange + red
  delay(3000);
  digitalWrite(ORANGE_LED, HIGH);
  
  //green
  delay(2000);
  digitalWrite(GREEN_LED, HIGH);
  digitalWrite(ORANGE_LED, LOW);
  digitalWrite(RED_LED, LOW);
  
  //orange
  delay(3000);
  digitalWrite(ORANGE_LED, HIGH);
  digitalWrite(GREEN_LED, LOW);
  
  delay(2000);
}

void loop()
{
  
  while(1)
  {
    mode mode = NIGHT;

    bool state = digitalRead(BUTTON);

    //ked sa stlaci tlacidlo
    if(state == HIGH)
    {
      if(mode == NIGHT)
      {
          mode = DAY; 
      }else{
          mode = NIGHT; 
      }
    }
    
    if(mode == NIGHT)
    {
      night_mode();
    }else{
      day_mode();	 
    }
  }
  
}