亿迅智能制造网
工业4.0先进制造技术信息网站!
首页 | 制造技术 | 制造设备 | 工业物联网 | 工业材料 | 设备保养维修 | 工业编程 |
home  MfgRobots >> 亿迅智能制造网 >  >> Manufacturing Technology >> 制造工艺

带有 3 向复音的 Arduino Nano 上的生日快乐旋律

组件和用品

Arduino Nano R3
× 1

应用和在线服务

Arduino IDE

关于这个项目

在 Arduino Nano 上播放复调“生日快乐”主题,单个迷你面包板上的三个蜂鸣器。

首先——演示

将这个东西插入任何 USB 电源(不仅仅是计算机),它会无限期地播放“生日快乐”旋律......几乎......直到你真的厌倦了它=]

顺便说一句,相应通道/蜂鸣器中的每个音符变化都会使灯闪烁。

原理图

这个想法是制作一个(几乎)没有焊接的超级紧凑的设备。

最终,我设法在一个像这样的小面包板上安装了所需的一切:

面包板内部的孔是这样互连的:

这里的诀窍是 Arduino Nano 板适合这样的面包板,完美地允许我们在面包板的两侧连接一些额外的组件。

对不起,伙计们......我懒得在这里画任何图表,但这个案例太简单了,我相信这些特写足以弄清楚一切=]

如您所见,我在这里使用的是 Gravitech 的 Arduino Nano v3.0 板,但任何模拟都可以。这里的蜂鸣器和 LED 是非常普通的。它们实际上不必匹配任何特殊参数。

这里的电阻是100欧姆的……虽然LED过载保护的常见“标准”是220欧姆……但谁在乎……¯\_(ツ)_/¯

在这些照片中,唯一可能不太明显的是蜂鸣器的引脚是这样插入面包板的:

另请注意,中间的一个比其他的大-那是因为这个用于“低音”音乐频道☝🏻

... 只是在开玩笑! ^__^他们都像疯狂的老鼠合唱团一样吱吱作响,声音能力完全没有区别=]

因此,如果您愿意,可以毫无问题地使用三个相同的蜂鸣器,但是您必须将它们放置在面包板上略有不同的位置,并且还必须根据新蜂鸣器的位置更改程序代码中的输出引脚编号。

另外,请注意这里的另一个小“黑客”......无论如何我们在 Hack 斯特在这里还是什么? =] 所以我使用了几个 Arduino 的 I/O 将此处固定为 接地 蜂鸣器和 LED 的引脚 😱😱 .是的,这是正确的。实际上,如果您将程序中的任何 Arduino I/O 引脚设置为“低”状​​态,那么您可以像使用 Arduino 板上的标准 GND 引脚一样使用这些引脚。酷,对吧?;)

关于程序...

下面提供了 Arduino IDE 草图的完整列表。但是,您必须安装一个额外的“Tone”库才能编译您可以在此处下载的草图:

https://www.dropbox.com/s/q1udxg4yi47emeo/Tone.zip?dl=0

(如果有一个带有а注册“提案”的弹出窗口,只需用角落里的“x”按钮关闭它)

安装此库的最简单方法如下:在 Arduino IDE 主菜单中选择 Sketch - Include Library - Add .ZIP Library... 然后选择您下载的 zip 文件... еeasy¯\_(ツ)_/¯

该库对于在单个控制器上同时生成多个音调是必要的(它使用一些额外的硬件计时器和“幕后”硬件中断来实现此目标)。简单地说,它是在没有任何操作系统的单个处理器内核上进行的某种“乡下人多任务处理”=]

顺便说一句,这是图书馆的作者(感谢兄弟!=]):

http://playground.arduino.cc/Profiles/Bhagman

...以及图书馆的 GitHub 页面:

https://github.com/bhagman/Tone

免责声明🙂:
坦率地说,我这里的程序代码相当庞大且难以阅读。这主要是因为需要从一个线性命令流中同时“处理”三个“独立”的旋律线程。我真的想稍后重构代码,以便能够将旋律彼此分开并在将来使用它来播放不同的歌曲......但我可能不会=]

所以祝你好运。任何反馈表示赞赏。

感谢您阅读到最后 =]

代码

  • 生日快乐
Happy_birthdayArduino
不要忘记安装 Tone 库!!
#include Tone solo;Tone bass;Tone rythm;const int t =600; // 四音符持续时间const int tt =t*2;const int t14 =round(t*1/4);const int t24 =round(t*2/4);const int t34 =round(t*3/4);const int bassLedPin =15; // 低音 LED 信号引脚(又名 A1)const int rythmLedPin =17; // 节奏 LED 信号引脚(又名 A3)const int soloLedPin =19; // 独奏 LED 信号引脚(又名 A5)void wait(Tone t){ while (t.isPlaying()) { } }int bassLedState =LOW;void switchBassLed(){ if (bassLedState ==LOW) bassLedState =HIGH;否则bassLedState =LOW;数字写入(bassLedPin,bassLedState);}int rythmLedState =LOW;void switchRythmLed(){ if(rythmLedState ==LOW)rythmLedState =HIGH;否则 rythmLedState =低; digitalWrite(rythmLedPin, rythmLedState);}int soloLedState =LOW;void switchSoloLed(){ if (soloLedState ==LOW) soloLedState =HIGH;否则 soloLedState =低; digitalWrite(soloLedPin, soloLedState);}void setup(void){ pinMode(14, OUTPUT); // LED 接地引脚(又名 A0) pinMode(16, OUTPUT); // LED 接地引脚(又名 A2) pinMode(18, OUTPUT); // LED 接地引脚(又名 A4) pinMode(bassLedPin, OUTPUT); // 低音 LED 信号引脚 pinMode(rythmLedPin, OUTPUT); // 节奏 LED 信号引脚 pinMode(soloLedPin, OUTPUT); // 独奏 LED 信号引脚 pinMode(2, OUTPUT); // 独奏蜂鸣器接地引脚 pinMode(9, OUTPUT); // 节奏蜂鸣器接地引脚 solo.begin(6); // 独奏蜂鸣器信号引脚bass.begin(12); // 低音蜂鸣器信号引脚 rythm.begin(0); // 节奏蜂鸣器信号引脚 solo.play(NOTE_D4, t34); switchSoloLed();等待(独奏); solo.play(NOTE_D4, t14); switchSoloLed(); wait(solo);}void loop(void){bass.play(NOTE_G3, t); switchBassLed(); rythm.play(NOTE_G4, t24); switchRythmLed(); solo.play(NOTE_E4, t); switchSoloLed();等待(节奏); rythm.play(NOTE_B4, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_D5, t14); switchRythmLed();等待(节奏);bass.play(注意_B3,t); switchBassLed(); rythm.play(NOTE_G4, t24); switchRythmLed(); solo.play(NOTE_D4, t); switchSoloLed();等待(节奏); rythm.play(NOTE_B4, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_D5, t14); switchRythmLed();等待(节奏);bass.play(NOTE_D4,t); switchBassLed(); rythm.play(NOTE_G4, t24); switchRythmLed(); solo.play(NOTE_G4, t); switchSoloLed();等待(节奏); rythm.play(NOTE_B4, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_D5, t14); switchRythmLed();等待(节奏);bass.play(NOTE_D4,t); switchBassLed(); rythm.play(NOTE_D5, t24); switchRythmLed(); solo.play(NOTE_FS4, tt); switchSoloLed();等待(节奏); rythm.play(NOTE_FS5, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_A5, t14); switchRythmLed();等待(节奏);bass.play(注意_FS4,t); switchBassLed(); rythm.play(NOTE_D5, t24); switchRythmLed();等待(节奏); rythm.play(NOTE_FS5, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_A5, t14); switchRythmLed();等待(节奏);bass.play(注意_A4,t); switchBassLed(); rythm.play(NOTE_D5, t24); switchRythmLed(); solo.play(NOTE_D4, t34); switchSoloLed();等待(节奏); rythm.play(NOTE_FS5, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_A5, t14); switchRythmLed(); solo.play(NOTE_D4, t14); switchSoloLed();等待(节奏);bass.play(NOTE_D4,t); switchBassLed(); rythm.play(NOTE_D5, t24); switchRythmLed(); solo.play(NOTE_E4, t); switchSoloLed();等待(节奏); rythm.play(NOTE_FS5, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_A5, t14); switchRythmLed();等待(节奏);低音播放(注意_FS4,t); switchBassLed(); rythm.play(NOTE_D5, t24); switchRythmLed(); solo.play(NOTE_D4, t); switchSoloLed();等待(节奏); rythm.play(NOTE_FS5, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_A5, t14); switchRythmLed();等待(节奏);低音播放(注意_A4,t); switchBassLed(); rythm.play(NOTE_D5, t24); switchRythmLed(); solo.play(NOTE_A4, t); switchSoloLed();等待(节奏); rythm.play(NOTE_FS5, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_A5, t14); switchRythmLed();等待(节奏);低音播放(注意_G3,t); switchBassLed(); rythm.play(NOTE_G4, t24); switchRythmLed(); solo.play(NOTE_G4, tt); switchSoloLed();等待(节奏); rythm.play(NOTE_B4, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_D5, t14); switchRythmLed();等待(节奏);bass.play(注意_B3,t); switchBassLed(); rythm.play(NOTE_G4, t24); switchRythmLed();等待(节奏); rythm.play(NOTE_B4, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_D5, t14); switchRythmLed();等待(节奏);低音播放(NOTE_D4,t); switchBassLed(); rythm.play(NOTE_G4, t24); switchRythmLed(); solo.play(NOTE_D4, t34); switchSoloLed();等待(节奏); rythm.play(NOTE_B4, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_D5, t14); switchRythmLed(); solo.play(NOTE_D4, t14); switchSoloLed();等待(节奏);bass.play(注意_G3,t); switchBassLed(); rythm.play(NOTE_G4, t24); switchRythmLed(); solo.play(NOTE_D5, t); switchSoloLed();等待(节奏); rythm.play(NOTE_B4, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_D5, t14); switchRythmLed();等待(节奏);低音播放(注意_B3,t); switchBassLed(); rythm.play(NOTE_G4, t24); switchRythmLed(); solo.play(NOTE_B4, t); switchSoloLed();等待(节奏); rythm.play(NOTE_B4, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_D5, t14); switchRythmLed();等待(节奏);低音播放(NOTE_D4,t); switchBassLed(); rythm.play(NOTE_G4, t24); switchRythmLed(); solo.play(NOTE_G4, t); switchSoloLed();等待(节奏); rythm.play(NOTE_B4, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_D5, t14); switchRythmLed();等待(节奏);低音播放(注意_C4,t); switchBassLed(); rythm.play(NOTE_C5, t24); switchRythmLed(); solo.play(NOTE_FS4, t); switchSoloLed();等待(节奏); rythm.play(NOTE_E5, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_G5, t14); switchRythmLed();等待(节奏);低音播放(注意_E4,t); switchBassLed(); rythm.play(NOTE_C5, t24); switchRythmLed(); solo.play(NOTE_E4, t); switchSoloLed();等待(节奏); rythm.play(NOTE_E5, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_G5, t14); switchRythmLed();等待(节奏);低音播放(注意_G4,t); switchBassLed(); rythm.play(NOTE_C5, t24); switchRythmLed(); solo.play(NOTE_C5, t34); switchSoloLed();等待(节奏); rythm.play(NOTE_E5, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_G5, t14); switchRythmLed(); solo.play(NOTE_C5, t14); switchSoloLed();等待(节奏);bass.play(注意_G3,t); switchBassLed(); rythm.play(NOTE_G4, t24); switchRythmLed(); solo.play(NOTE_B4, t); switchSoloLed();等待(节奏); rythm.play(NOTE_B4, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_D5, t14); switchRythmLed();等待(节奏);低音播放(NOTE_D3,t); switchBassLed(); rythm.play(NOTE_G4, t24); switchRythmLed(); solo.play(NOTE_G4, t); switchSoloLed();等待(节奏); rythm.play(NOTE_B4, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_D5, t14); switchRythmLed();等待(节奏);低音播放(注意_FS3,t); switchBassLed(); rythm.play(NOTE_D5, t24); switchRythmLed(); solo.play(NOTE_A4, t); switchSoloLed();等待(节奏);等待(节奏); rythm.play(NOTE_FS5, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_A5, t14); switchRythmLed();等待(节奏);低音播放(注意_G3,t); switchBassLed(); rythm.play(NOTE_G4, t24); switchRythmLed(); solo.play(NOTE_G4, tt); switchSoloLed();等待(节奏); rythm.play(NOTE_B4, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_D5, t14); switchRythmLed();等待(节奏);bass.play(注意_B3,t); switchBassLed(); rythm.play(NOTE_G4, t24); switchRythmLed();等待(节奏); rythm.play(NOTE_B4, t14); switchRythmLed();等待(节奏); rythm.play(NOTE_D5, t14); switchRythmLed();等待(节奏); solo.play(NOTE_D4, t34); switchSoloLed();等待(独奏); solo.play(NOTE_D4, t14); switchSoloLed();等待(单人);}

制造工艺

  1. 使用 K30 传感器监测二氧化碳
  2. 聋盲通信与 1Sheeld/Arduino
  3. 使用 Arduino 控制硬币接收器
  4. 鲜花 - Arduino Nano、CrazyCircuits、DFRobot
  5. Arduino 带蓝牙控制 LED!
  6. 带有 Arduino 或 ESP8266 的电容式指纹传感器
  7. 玩 Nextion Display
  8. Nunchuk 控制机械臂(使用 Arduino)
  9. Arduino Nano:使用操纵杆控制 2 个步进电机
  10. 带有 Arduino Nano 的手持盖革计数器
  11. 使用 Arduino 测量太阳辐射
  12. 带 Arduino 的迷你雷达