Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ to generate tones, similar to [`tone()`](https://www.arduino.cc/reference/en/lan
2. [El Ninio del Tambor](https://youtu.be/wsMXWFXqSFE?si=DsfSel4m0bFxvVdt) :child::drum: (_Rompomponpon_)
3. [La Cucaracha](https://youtu.be/BZ3bY_j_11I?si=7EHdJrBd9Wp2K_e8) :cockroach::mexico:
4. [Los Peces en el Rio](https://www.youtube.com/watch?v=tfMDXnsuJFg) :fish::fish:
4. [Mi Burrito Sabanero](https://www.youtube.com/watch?v=UsgSq2g9Cks) :racehorse::bell:

## Trying it out!
Follow the [Quick-start your own project](https://github.com/raspberrypi/pico-sdk/tree/master#quick-start-your-own-project) from [`pico-sdk`](https://github.com/raspberrypi/pico-sdk)
Expand Down
171 changes: 170 additions & 1 deletion melodies.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
*/
#include "melodies.h"

uint32_t note_duration_in_ms = 500;

uint32_t get_note_duration_in_ms(float note_duration) {
return (uint32_t)(note_duration * NOTE_DURATION);
return (uint32_t)(note_duration * note_duration_in_ms);
}

void play_tone(uint gpio, uint32_t frequency, float duration) {
Expand Down Expand Up @@ -468,3 +470,170 @@ void play_peces_en_el_rio(uint gpio) {
sleep_ms(get_note_duration_in_ms(1.f));
}
}

void con_mi_burrito_sabanero(uint gpio) {
for (int i=0; i<2; i++) {
for (int j=0; j<2; j++) {
// 1
sleep_ms(get_note_duration_in_ms(.5f));
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_G4, .5f);

// 2
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_G4, .5f);

// 3
play_tone(gpio, NOTE_C5, .5 + .25f);
play_tone(gpio, NOTE_C5, .5f);
play_tone(gpio, NOTE_C5, .5f);
play_tone(gpio, NOTE_C5, .5f);

// 4
play_tone(gpio, NOTE_A4, .5f);
play_tone(gpio, NOTE_A4, .5f);
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_A4, .5f);
play_tone(gpio, NOTE_B4, .5f);
}
for (int j=0; j<2; j++) {
// 5
sleep_ms(get_note_duration_in_ms(1.f));
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_G4, .5f);

// 6
play_tone(gpio, NOTE_E4, 1.f);
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_G4, .5f);

// 7
play_tone(gpio, NOTE_D4, 1.f);
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_B4, .5f);

// 8
play_tone(gpio, NOTE_A4, .5f);
play_tone(gpio, NOTE_A4, .5f);

// 9
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_G4, .5f);
}
}
}

void play_mi_burrito_sabanero(uint gpio) {
// Play mi burrito sabanero
con_mi_burrito_sabanero(gpio);
/// Dunki dunki dunki dunki
// 10
sleep_ms(get_note_duration_in_ms(1.f));
sleep_ms(get_note_duration_in_ms(1.f));

// 11 & 12
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_B4, .5f + .5f);
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_A4, .5f);

// 13
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_G4, .5f);
sleep_ms(get_note_duration_in_ms(1.f));

// 14
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_B4, .5f + .5f);
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_A4, .5f);

// 15
play_tone(gpio, NOTE_G4, 1.f);
play_tone(gpio, NOTE_A4, .5f);
play_tone(gpio, NOTE_A4, .5f);

// 16
play_tone(gpio, NOTE_A4, .5f);
play_tone(gpio, NOTE_A4, .5f);
play_tone(gpio, NOTE_A4, .5f);
play_tone(gpio, NOTE_G4, .5f);

// 17
play_tone(gpio, NOTE_A4, 1.f);
play_tone(gpio, NOTE_A4, .5f);
play_tone(gpio, NOTE_A4, .5f);

// 18
play_tone(gpio, NOTE_A4, .5f);
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_E4, .5f);

// 19
play_tone(gpio, NOTE_D4, 1.f);
sleep_ms(get_note_duration_in_ms(1.f));

// 20
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_B4, .5f + .5f);
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_A4, .5f);

// 21
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_G4, .5f);
sleep_ms(get_note_duration_in_ms(1.f));

// 22
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_B4, .5f + .5f);
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_A4, .5f);

// 23
play_tone(gpio, NOTE_G4, 1.f);
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_G4, .5f);

// 24
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_G4, .5f);

// 25
play_tone(gpio, NOTE_B4, .5f);
play_tone(gpio, NOTE_G4, .5f);

// 26
play_tone(gpio, NOTE_D4, .5f);
play_tone(gpio, NOTE_B4, .5f);

// 27
play_tone(gpio, NOTE_A4, .5f);
play_tone(gpio, NOTE_G4, .5f);

// 28
play_tone(gpio, NOTE_G4, .5f);
play_tone(gpio, NOTE_A4, .5f);

// 29
play_tone(gpio, NOTE_G4, .5f);
sleep_ms(get_note_duration_in_ms(1.5f));

// 30
con_mi_burrito_sabanero(gpio);
}
14 changes: 13 additions & 1 deletion melodies.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*
*/

extern uint32_t note_duration_in_ms;
// NOTE_DURATION is the speed of each note in ms
#define NOTE_DURATION 400U // Speed of each note in ms
#define SILENCE_AFTER_NOTE 10U // Speed of each note in ms


Expand Down Expand Up @@ -105,4 +105,16 @@ void play_el_ninio_del_tambor(uint gpio);
*/
void play_peces_en_el_rio(uint gpio);

/*! \bried Play 'Mi burrito sabanero' on the given GPIO pin (Part1)
*
* \param gpio The GPIO pin to play the melody on
*/
void con_mi_burrito_sabanero(uint gpio);

/*! \bried Play 'Mi burrito sabanero' on the given GPIO pin (Part2)
*
* \param gpio The GPIO pin to play the melody on
*/
void play_mi_burrito_sabanero(uint gpio);

#endif
7 changes: 7 additions & 0 deletions noisy_ornament.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@ int main() {
// Configure tone generation on BUZZER_PIN
tone_init(BUZZER_PIN);
while (1) {
note_duration_in_ms = 400;
play_silent_night(BUZZER_PIN);
// Stop playing to distinguish between melodies
no_tone(BUZZER_PIN);
sleep_ms(500);
//play_la_cucaracha(BUZZER_PIN);
note_duration_in_ms = 600;
play_el_ninio_del_tambor(BUZZER_PIN);
no_tone(BUZZER_PIN);
sleep_ms(500);
note_duration_in_ms = 400;
play_peces_en_el_rio(BUZZER_PIN);
no_tone(BUZZER_PIN);
sleep_ms(500);
note_duration_in_ms = 500;
play_mi_burrito_sabanero(BUZZER_PIN);
no_tone(BUZZER_PIN);
sleep_ms(500);
}
}