#define On HIGH
#define Off LOW
#define LED1 7
#define SW1 6

int SW_logic = 0;				// สร้าง Flag ขึ้นมา
int LED_state;

void setup() {
  pinMode(SW1, INPUT);  
  pinMode(LED1, OUTPUT);
  digitalWrite(LED1, Off);
  LED_state = 0;
}

void loop() {
  SW_logic = digitalRead(SW1);
  if (SW_logic == LOW)           // กดสวิตซ์ SW1
  {
    if (LED_state == 0){
      digitalWrite(LED1, On);
      LED_state = 1;
    } else if (LED_state == 1){
      digitalWrite(LED1, Off);
      LED_state = 0;
    }
  }
  delay(200);              // wait for a second
}