-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9c0bbd
commit b8580ba
Showing
3 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Day five: | ||
|
||
Play a Christmas carol (or a song you like) using the Barduino. | ||
|
||
Time to make some music! Use the buzzer (or any other thing!) to make some music, the idea is to play a Christmas carol. As we come from many different places, try to play one from your hometown, to have a nice collection of tunes :partying_face: | ||
|
||
Here is my version of *A Betlem m'en vull anar* | ||
|
||
## Possible solution! | ||
|
||
### Arduino code | ||
|
||
```c++ | ||
#include <Adafruit_NeoPixel.h> | ||
|
||
note_t notes[] = { NOTE_E, NOTE_F, NOTE_G, NOTE_G, NOTE_C, NOTE_A, NOTE_G, NOTE_MAX, NOTE_F, NOTE_E, NOTE_D, NOTE_E, NOTE_F, NOTE_G, NOTE_E, NOTE_C, NOTE_E, NOTE_F, NOTE_G, NOTE_G, NOTE_C, NOTE_A, NOTE_G, NOTE_MAX, NOTE_F, NOTE_E, NOTE_D, NOTE_F, NOTE_E, NOTE_G, NOTE_C }; | ||
//int notes2[] = {E, F, G, G, c, A, G, M, F, E, D, E, F, G, E, C, E, F, G, G, c, A, G, M, F, E, D, F, E, G, C}; | ||
int tempos[] = { 1, 1, 2, 2, 2, 2, 4, 2, 1, 1, 2, 2, 2, 2, 4, 2, 1, 1, 2, 2, 2, 2, 4, 2, 1, 1, 2, 2, 2, 2, 4 }; | ||
int octave[] = { 4, 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }; | ||
|
||
const int buzzer = 14; | ||
const int tempo = 130; | ||
|
||
#define PIN 38 | ||
#define NUMPIXELS 1 | ||
|
||
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); | ||
|
||
int hue = 0; | ||
int hueInterval = 65535 / 31; | ||
|
||
void setup() { | ||
ledcAttachPin(buzzer, 1); | ||
Serial.begin(115200); | ||
for (int i = 0; i < 31; i++) { | ||
if (notes[i] != NOTE_MAX) { | ||
ledcWriteNote(1, notes[i], octave[i]); | ||
} else { | ||
ledcWriteTone(1, 0); | ||
} | ||
pixels.setPixelColor(0, pixels.ColorHSV(hue, 255, 255)); | ||
pixels.show(); | ||
hue = hue + hueInterval; | ||
delay(tempo * tempos[i]); | ||
} | ||
ledcWriteTone(1, 0); | ||
pixels.setPixelColor(0, pixels.ColorHSV(hue, 0, 0)); | ||
pixels.show(); | ||
} | ||
|
||
void loop() { | ||
} | ||
|
||
``` | ||
|
||
## Hero shot | ||
|
||
<video controls autoplay loop style="display: block; margin: auto;"> | ||
<source src="../../../video/day05.mp4" type="video/mp4"> | ||
</video> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters