这是我的课堂(4)——电子钢琴
2017-11-181.7万
AI 快速预览详细
本文介绍了如何使用Arduino制作一个电子钢琴。通过定义不同音符的频率(如C=523Hz),并连接按钮和音响,可以实现简单的音乐播放。文中提供了详细的代码和接线图,适合初学者和STEM教育场景。这个项目不仅能够激发孩子的创造力,还能让他们在动手实践中体验音乐创作的乐趣。
|
这次我们来做一个电子钢琴 认识按钮与音响的结合 [mw_shl_code=applescript,true]#define C 523 #define D 587 #define E 659 #define G 698 #define A 784 const int yin=9; const int BC=7; const int BD=6; const int BE=5; const int BG=4; const int BA=3; void setup() { // put your setup code here, to run once: } void loop() { while(digitalRead(BC)) tone(yin,C); while(digitalRead (BD)) tone(yin,D); while(digitalRead(BE)) tone(yin,E); while(digitalRead(BG)) tone(yin,G); while(digitalRead(BA)) tone(yin,A); noTone(yin);// put your main code here, to run repeatedly: } [/mw_shl_code] 由于时间关系这里不多说 接线如下 音响=9 按钮分别=7 6 5 4 3 |



