Dans ce tutoriel nous allons voir comment reproduire la musique du célébré film Star Wars et cela avec Un arduino, un buzzer et quelques LEDs comme ceci:
De quoi avons nous besoin:
- 2x Resistances ( Disponible ici)
- 1x Buzzer ( Disponible ici)
- 5x Jumpers ( Disponible ici)
- 1x Arduino Uno ( Disponible ici)
- 1x Breadboard ( Disponible ici)
Passons maintenant au montage
Et maintenant le Code
[pastacode « c » manual= »const%20int%20c%20%3D%20261%3B%0Aconst%20int%20d%20%3D%20294%3B%0Aconst%20int%20e%20%3D%20329%3B%0Aconst%20int%20f%20%3D%20349%3B%0Aconst%20int%20g%20%3D%20391%3B%0Aconst%20int%20gS%20%3D%20415%3B%0Aconst%20int%20a%20%3D%20440%3B%0Aconst%20int%20aS%20%3D%20455%3B%0Aconst%20int%20b%20%3D%20466%3B%0Aconst%20int%20cH%20%3D%20523%3B%0Aconst%20int%20cSH%20%3D%20554%3B%0Aconst%20int%20dH%20%3D%20587%3B%0Aconst%20int%20dSH%20%3D%20622%3B%0Aconst%20int%20eH%20%3D%20659%3B%0Aconst%20int%20fH%20%3D%20698%3B%0Aconst%20int%20fSH%20%3D%20740%3B%0Aconst%20int%20gH%20%3D%20784%3B%0Aconst%20int%20gSH%20%3D%20830%3B%0Aconst%20int%20aH%20%3D%20880%3B%0A%0Aconst%20int%20buzzerPin%20%3D%208%3B%20%2F%2F%20Digital%20Pin%208%0Aconst%20int%20ledPin1%20%3D%2012%3B%20%20%2F%2F%20Digital%20Pin%2012%0Aconst%20int%20ledPin2%20%3D%2013%3B%20%20%2F%2F%20Digital%20Pin%2013%20Built%20In%20Led%20can%20Change%20it%20if%20you%20want%0A%0Aint%20counter%20%3D%200%3B%0A%0Avoid%20setup()%0A%7B%0A%20%20%2F%2FSetup%20pin%20modes%0A%20%20pinMode(buzzerPin%2C%20OUTPUT)%3B%20%2F%2F%20Digital%20Pin%208%0A%20%20pinMode(ledPin1%2C%20OUTPUT)%3B%20%20%2F%2F%20Digital%20Pin%2012%0A%20%20pinMode(ledPin2%2C%20OUTPUT)%3B%20%2F%2F%20Digital%20Pin%2013%20Built%20In%20Led%20can%20Change%20it%20if%20you%20want%0A%7D%0A%0Avoid%20loop()%0A%7B%0A%0A%20%20%2F%2FPlay%20first%20section%0A%20%20firstSection()%3B%0A%0A%20%20%2F%2FPlay%20second%20section%0A%20%20secondSection()%3B%0A%0A%20%20%2F%2FVariant%201%0A%20%20beep(f%2C%20250)%3B%20%20%0A%20%20beep(gS%2C%20500)%3B%20%20%0A%20%20beep(f%2C%20350)%3B%20%20%0A%20%20beep(a%2C%20125)%3B%0A%20%20beep(cH%2C%20500)%3B%0A%20%20beep(a%2C%20375)%3B%20%20%0A%20%20beep(cH%2C%20125)%3B%0A%20%20beep(eH%2C%20650)%3B%0A%0A%20%20delay(500)%3B%0A%0A%20%20%2F%2FRepeat%20second%20section%0A%20%20secondSection()%3B%0A%0A%20%20%2F%2FVariant%202%0A%20%20beep(f%2C%20250)%3B%20%20%0A%20%20beep(gS%2C%20500)%3B%20%20%0A%20%20beep(f%2C%20375)%3B%20%20%0A%20%20beep(cH%2C%20125)%3B%0A%20%20beep(a%2C%20500)%3B%20%20%0A%20%20beep(f%2C%20375)%3B%20%20%0A%20%20beep(cH%2C%20125)%3B%0A%20%20beep(a%2C%20650)%3B%20%20%0A%0A%20%20delay(650)%3B%0A%7D%0A%0Avoid%20beep(int%20note%2C%20int%20duration)%0A%7B%0A%20%20%2F%2FPlay%20tone%20on%20buzzerPin%0A%20%20tone(buzzerPin%2C%20note%2C%20duration)%3B%0A%0A%20%20%2F%2FPlay%20different%20LED%20depending%20on%20value%20of%20’counter’%0A%20%20if(counter%20%25%202%20%3D%3D%200)%0A%20%20%7B%0A%20%20%20%20digitalWrite(ledPin1%2C%20HIGH)%3B%0A%20%20%20%20delay(duration)%3B%0A%20%20%20%20digitalWrite(ledPin1%2C%20LOW)%3B%0A%20%20%7Delse%0A%20%20%7B%0A%20%20%20%20digitalWrite(ledPin2%2C%20HIGH)%3B%0A%20%20%20%20delay(duration)%3B%0A%20%20%20%20digitalWrite(ledPin2%2C%20LOW)%3B%0A%20%20%7D%0A%0A%20%20%2F%2FStop%20tone%20on%20buzzerPin%0A%20%20noTone(buzzerPin)%3B%0A%0A%20%20delay(50)%3B%0A%0A%20%20%2F%2FIncrement%20counter%0A%20%20counter%2B%2B%3B%0A%7D%0A%0Avoid%20firstSection()%0A%7B%0A%20%20beep(a%2C%20500)%3B%0A%20%20beep(a%2C%20500)%3B%20%20%20%20%0A%20%20beep(a%2C%20500)%3B%0A%20%20beep(f%2C%20350)%3B%0A%20%20beep(cH%2C%20150)%3B%20%20%0A%20%20beep(a%2C%20500)%3B%0A%20%20beep(f%2C%20350)%3B%0A%20%20beep(cH%2C%20150)%3B%0A%20%20beep(a%2C%20650)%3B%0A%0A%20%20delay(500)%3B%0A%0A%20%20beep(eH%2C%20500)%3B%0A%20%20beep(eH%2C%20500)%3B%0A%20%20beep(eH%2C%20500)%3B%20%20%0A%20%20beep(fH%2C%20350)%3B%0A%20%20beep(cH%2C%20150)%3B%0A%20%20beep(gS%2C%20500)%3B%0A%20%20beep(f%2C%20350)%3B%0A%20%20beep(cH%2C%20150)%3B%0A%20%20beep(a%2C%20650)%3B%0A%0A%20%20delay(500)%3B%0A%7D%0A%0Avoid%20secondSection()%0A%7B%0A%20%20beep(aH%2C%20500)%3B%0A%20%20beep(a%2C%20300)%3B%0A%20%20beep(a%2C%20150)%3B%0A%20%20beep(aH%2C%20500)%3B%0A%20%20beep(gSH%2C%20325)%3B%0A%20%20beep(gH%2C%20175)%3B%0A%20%20beep(fSH%2C%20125)%3B%0A%20%20beep(fH%2C%20125)%3B%20%20%20%20%0A%20%20beep(fSH%2C%20250)%3B%0A%0A%20%20delay(325)%3B%0A%0A%20%20beep(aS%2C%20250)%3B%0A%20%20beep(dSH%2C%20500)%3B%0A%20%20beep(dH%2C%20325)%3B%20%20%0A%20%20beep(cSH%2C%20175)%3B%20%20%0A%20%20beep(cH%2C%20125)%3B%20%20%0A%20%20beep(b%2C%20125)%3B%20%20%0A%20%20beep(cH%2C%20250)%3B%20%20%0A%0A%20%20delay(350)%3B%0A%7D » message= » » highlight= » » provider= »manual »/]
Voila vous n’avez plus qu’a vous amuser 😀