- 준비물
- 3색 LED 1개 - 코드
//ouput pin 설정 const int ledRedPin = 11; const int ledGreenPin = 10; const int ledBluePin = 9; void setup() { //random으로 출력되는 숫자의 변경을 위해 seed 설정 randomSeed(analogRead(A0)); } void loop() { // random하게 값 지정(0~225) analogWrite(ledRedPin, random(256)); analogWrite(ledGreenPin, random(256)); analogWrite(ledBluePin, random(256)); delay(1000); }
- 영상
- 알게된 점
- analogRead로 읽을 수 있는 값의 범위는 0 ~ 1023
- analogRead의 경우도 digitalRead와 마찬가지 값이 플로팅 됨(0~1023 값이 랜덤)
'프로그래밍 > Arduino' 카테고리의 다른 글
미니 디지털 피아노 (0) | 2017.04.12 |
---|---|
Piezo 스피커로 도레미파솔라시도 연주 (0) | 2017.04.12 |
Serial 통신하기 (0) | 2017.04.07 |
버튼스위치를 사용하여 3색 LED 색 바꾸기 (0) | 2017.04.06 |
버튼스위치를 사용하여 LED 켜기 (2) | 2017.04.06 |