방탄소년단 버터의 멜로디를 아두이노 피에조 부저를 이용하여 재생하는 코드입니다.
아두이노 우노 / NodeMcu / ESP32 DevKit용 예제 스케치입니다.
uint8_t Tempo = 110;
float tempoRatio = float(Tempo)/60.0;
uint8_t KeySign = 4;
uint8_t octaveTemp = 4;
// float beatTime = 4/4; // 박자표 - 멜로디 코드에서는 사용하지 않는다.(Simple Melody 앱만 사용)
const note_t Mnote[] PROGMEM= {
NOTE_G,NOTE_F,NOTE_E,NOTE_C,NOTE_MAX,NOTE_A,NOTE_A,NOTE_G,NOTE_MAX,NOTE_G,NOTE_G,NOTE_F,NOTE_F,NOTE_E,NOTE_C,NOTE_MAX,NOTE_A,NOTE_G,NOTE_F,NOTE_E,NOTE_C,NOTE_MAX,NOTE_C,NOTE_C,NOTE_C,
NOTE_MAX,NOTE_D,NOTE_E,NOTE_A,NOTE_A,NOTE_A,NOTE_C,NOTE_MAX,NOTE_G,NOTE_F,NOTE_E,NOTE_C,NOTE_MAX,NOTE_A,NOTE_G,NOTE_MAX,NOTE_G,NOTE_G,NOTE_F,NOTE_F,NOTE_E,NOTE_C,NOTE_MAX,NOTE_MAX,
NOTE_G,NOTE_F,NOTE_E,NOTE_C,NOTE_MAX,NOTE_C,NOTE_C,NOTE_MAX,NOTE_D,NOTE_E,NOTE_A,NOTE_A,NOTE_A,NOTE_A,NOTE_MAX,NOTE_MAX,NOTE_E,NOTE_E,NOTE_E,NOTE_E,NOTE_MAX,NOTE_E,NOTE_E,NOTE_E,NOTE_A,
NOTE_MAX,NOTE_E,NOTE_E,NOTE_E,NOTE_E,NOTE_MAX,NOTE_E,NOTE_E,NOTE_A,NOTE_MAX,NOTE_E,NOTE_E,NOTE_E,NOTE_E,NOTE_MAX,NOTE_E,NOTE_E,NOTE_E,NOTE_A,NOTE_E,NOTE_F,NOTE_A,NOTE_B,NOTE_E,NOTE_E,NOTE_C,NOTE_E,NOTE_C,NOTE_E,
NOTE_C,NOTE_B,NOTE_MAX,NOTE_A,NOTE_G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딩하기(동요 겨울밤, 다람쥐, 옹달샘, 작은별)
[arduino] - arduino - Simple Melody 이용 피에조 부저 멜로디 코딩하기, Esp01, EEPROM
[arduino] - 아두이노 - 피에조 부저 멜로디 BTS DNA
반응형
'Arduino > Piezo Buzzer' 카테고리의 다른 글
아두이노 - 피에조 부저 멜로디 - 로제_브루노마스 아파트 (0) | 2024.11.29 |
---|---|
아두이노 - 피에조 부저 멜로디 - 아틀란티스 소녀 (0) | 2024.09.29 |
아두이노 - 피에조 부저 멜로디 - 조덕배 꿈에 (0) | 2024.09.27 |
아두이노 - 피에조 부저 멜로디 아기상어 (0) | 2024.09.04 |
피에조 부저 멜로디 - 동요: 햇볕은 쨍쨍 (0) | 2020.10.26 |
피에조 부저 멜로디 - 동요: 학교종 (0) | 2020.10.26 |
피에조 부저 멜로디 - 동요: 주먹 쥐고 손을 펴서 (0) | 2020.10.26 |
피에조 부저 멜로디 - 동요: 자전거 (0) | 2020.10.26 |