- 준비물
- 조도센서 1개
- piezo 스피커 1개
- 10㏀ 저항 1개 - 코드
- 영상
const int lightInputPin = A0;
const int piezoOutputPin = 8;
void setup() {
}
void loop() {
int light = analogRead(lightInputPin);//0(0V) ~ 1023(5V)
int hertz = map(light, 0, 1023, 31, 4978);
tone(piezoOutputPin, hertz, 100);
delay(100);
noTone(piezoOutputPin);
delay(200);
}
'프로그래밍 > Arduino' 카테고리의 다른 글
| 거리에 따른 piezo 스피커 출력시간 조절 (0) | 2017.04.14 |
|---|---|
| 거리에 따른 3색 LED 색 변경 (0) | 2017.04.14 |
| 주위 밝기에 따라 LED 빛 바꾸기 (0) | 2017.04.13 |
| 미니 디지털 피아노 (0) | 2017.04.12 |
| Piezo 스피커로 도레미파솔라시도 연주 (0) | 2017.04.12 |