페이지

2026년 6월 15일 월요일

5.1.4. 여러 개의 LED 제어하기 (신호등 만들기)





CODE 5.3 | 여러 개의 LED로 신호등 만들기 예시 코드
01int redPin = 10; // 빨간색 LED를 연결한 디지털 핀
02int yellowPin = 9; // 노란색 LED를 연결한 디지털 핀
03int greenPin = 8; // 초록색 LED를 연결한 디지털 핀
04 
05void setup() {
06  pinMode(redPin, OUTPUT); // 빨간색 LED 핀을 출력 모드로 설정
07  pinMode(yellowPin, OUTPUT); // 노란색 LED 핀을 출력 모드로 설정
08  pinMode(greenPin, OUTPUT); // 초록색 LED 핀을 출력 모드로 설정
09}
10 
11void loop() {
12  digitalWrite(greenPin, HIGH); // 초록색 LED 켜기
13  delay(3000); // 3초 대기
14  digitalWrite(greenPin, LOW); // 초록색 LED 끄기
15 
16  digitalWrite(yellowPin, HIGH); // 노란색 LED 켜기
17  delay(1000); // 1초 대기
18  digitalWrite(yellowPin, LOW); // 노란색 LED 끄기
19 
20  digitalWrite(redPin, HIGH); // 빨간색 LED 켜기
21  delay(3000); // 3초 대기
22  digitalWrite(redPin, LOW); // 빨간색 LED 끄기
23}



 

댓글 없음:

댓글 쓰기