Limetime's TimeLine
article thumbnail
Published 2023. 1. 4. 00:48
[Arduino] 디지털 피아노 C&C++/Arduino
반응형

피에조 스피커를 버튼에 따라 정해진 음이 재생되도록 설정하여 간단한 디지털 피아노를 만들어보자!

<cpp />
#define NOTE_C4 262 #define NOTE_D4 294 #define NOTE_E4 330 int pins[] = {2,3,4}; int notes[] = {NOTE_E4, NOTE_D4, NOTE_C4}; void setup() { // put your setup code here, to run once: for(int i = 0; i < 3; i++){ pinMode(pins[i], INPUT); } } void loop() { // put your main code here, to run repeatedly: for(int i = 0; i < 3; i++){ if(digitalRead(pins[i]) == HIGH){ tone(8, notes[i], 20); } } }

각각 도 레 미 라고 한다.(?..)

버튼과 주파수가 각각 1:1 매칭되어 있다고 보면 된다.

 

각 버튼에는 10K옴이 연결되어 있다.

 

 

 

반응형
profile

Limetime's TimeLine

@Limetime

포스팅이 좋았다면 "공감❤️" 또는 "구독👍🏻" 해주세요!