충북고등학교 로고이미지

수업과제제출

RSS 페이스북 공유하기 트위터 공유하기 카카오톡 공유하기 카카오스토리 공유하기 네이버밴드 공유하기 프린트하기
스위치 신호등
작성자 최창수 등록일 15.07.17 조회수 236
int led = 13;
int ledred = 12;
int ledgreen = 11;
int ledblue = 10;
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  3;
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
// he setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
   // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
  digitalWrite(ledred, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(ledred, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second}
  digitalWrite(ledgreen, HIGH);
  digitalWrite(ledblue, HIGH);// turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(ledgreen, LOW);
  digitalWrite(ledblue, LOW);// turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second}
 
  buttonState = digitalRead(buttonPin);

  
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}
 
이전글 시노등
다음글 신호등