Skip to content

Commit

Permalink
day05
Browse files Browse the repository at this point in the history
  • Loading branch information
JosepMartiElias committed Dec 4, 2023
1 parent a5c55cb commit a85fdb2
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ hide:
1. -... .- .-. -.. ..- .. -. ---

!!! warning annotate "5. Jingle Bells! (1)"
[Day 05](solutions/05/05.md)
1. Sing with me

!!! question annotate "6. Barduino wishes you a Merry Christmas! (1)"
Expand Down
2 changes: 0 additions & 2 deletions docs/solutions/04/04.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ Here is my solution, using the LED and the buzzer. Try to do it yourself first,
### Arduino code

```c++
#include <ESP32Servo.h>

const int led = 48;
const int buzzer = 14;
const int freq = 800;
Expand Down
60 changes: 60 additions & 0 deletions docs/solutions/05/05.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Day four:

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>
Binary file added docs/video/day05.mp4
Binary file not shown.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +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
- Solution template:
- template.md

Expand Down

0 comments on commit a85fdb2

Please sign in to comment.