- 준비물
- piezo 스피커 1개
- 버튼스위치 3개
- 10㏀ 저항 3개 - 코드
- 영상
- 알게된 점
- tone에서 정한 출력시간 만큼 delay를 해줘야 음이 겹치지 않고 충분히 출력(당연한얘기를..)
//input Pin 배열 int inputArr[] = {2, 3, 4}; int inputArrSize = sizeof(inputArr)/sizeof(int); //음 배열 int soundArr[] = {262, 294, 330}; int soundArrSize = sizeof(soundArr)/sizeof(int); //piezo 출력 핀 const int outputPiezoPin = 8; void setup() { for(int i=0 ; i< inputArrSize ; i++) { pinMode(inputArr[i], INPUT); } } void loop() { for(int i=0 ; i< soundArrSize ; i++) { if(digitalRead(inputArr[i]) == HIGH) { tone(outputPiezoPin, soundArr[i], 100); delay(100); noTone(outputPiezoPin); } } }
'프로그래밍 > Arduino' 카테고리의 다른 글
주위 밝기에 따라 piezo 스피커 음 변경 (0) | 2017.04.13 |
---|---|
주위 밝기에 따라 LED 빛 바꾸기 (0) | 2017.04.13 |
Piezo 스피커로 도레미파솔라시도 연주 (0) | 2017.04.12 |
랜덤으로 LED 색 바꾸기 (0) | 2017.04.12 |
Serial 통신하기 (0) | 2017.04.07 |