From b8580ba667ac1458d27a3fd961628010d18aaeb0 Mon Sep 17 00:00:00 2001 From: josepmarti Date: Thu, 5 Dec 2024 10:13:28 +0100 Subject: [PATCH] Day05 --- docs/index.md | 3 +-- docs/solutions/05/05.md | 60 +++++++++++++++++++++++++++++++++++++++++ mkdocs.yml | 2 +- 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 docs/solutions/05/05.md diff --git a/docs/index.md b/docs/index.md index 81041a0..300b4a8 100644 --- a/docs/index.md +++ b/docs/index.md @@ -23,8 +23,7 @@ hide: 1. -... .- .-. -.. ..- .. -. --- !!! warning annotate "5. Jingle Bells! (1)" - Day 05 - [](solutions/05/05.md) + [Day 05](solutions/05/05.md) 1. Sing with me !!! question annotate "6. Barduino wishes you a Merry Christmas! (1)" diff --git a/docs/solutions/05/05.md b/docs/solutions/05/05.md new file mode 100644 index 0000000..86d7d96 --- /dev/null +++ b/docs/solutions/05/05.md @@ -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 + +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 + + \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 797d127..12c1171 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -17,7 +17,7 @@ nav: - Day 2: solutions/02/02.md - Day 3: solutions/03/03.md - Day 4: solutions/04/04.md - #- Day 5: solutions/05/05.md + - Day 5: solutions/05/05.md #- Day 6: solutions/06/06.md #- Day 7: solutions/07/07.md #- Day 8: solutions/08/08.md