|
Serial Musical Organ 1.0
Buzzer controller and musical organ
|
Implementation of pre-defined songs for musical organ. More...
#include "includes/CPU.h"#include <avr/io.h>#include <util/delay.h>#include "includes/scale16.h"#include "includes/organ.h"#include "includes/pre_defined_songs.h"
Go to the source code of this file.
Macros | |
| #define | _num_notes(x) sizeof(x) / sizeof(x[0]) |
Functions | |
| void | play_twinkle_little_star () |
| Plays "Twinkle Twinkle Little Star" melody. | |
Implementation of pre-defined songs for musical organ.
This file contains the actual implementations of all pre-programmed songs. Each song is defined as arrays of notes (frequencies) and durations (milliseconds), then played sequentially using playNote().
Definition in file pre_defined_songs.c.
| #define _num_notes | ( | x | ) | sizeof(x) / sizeof(x[0]) |
| void play_twinkle_little_star | ( | ) |
Plays "Twinkle Twinkle Little Star" melody.
Implements the complete Twinkle Twinkle Little Star song using fixed note durations (Q=250ms for eighth notes, H=500ms for quarter notes). The song has 42 notes organized in 6 phrases of 7 notes each.
* Phrase 1: C4 C4 G4 G4 A4 A4 G4 (Twinkle twinkle little star) * Phrase 2: F4 F4 E4 E4 D4 D4 C4 (How I wonder what you are) * Phrase 3: G4 G4 F4 F4 E4 E4 D4 (Up above the world so high) * Phrase 4: G4 G4 F4 F4 E4 E4 D4 (Like a diamond in the sky) * Phrase 5: C4 C4 G4 G4 A4 A4 G4 (Twinkle twinkle little star) * Phrase 6: F4 F4 E4 E4 D4 D4 C4 (How I wonder what you are) *
| Note | Frequency (Hz) | Period (μs) | Timer Value |
|---|---|---|---|
| C4 | 261.63 | 3822 | 1911 |
| D4 | 293.66 | 3405 | 1702 |
| E4 | 329.63 | 3033 | 1516 |
| F4 | 349.23 | 2863 | 1431 |
| G4 | 392.00 | 2551 | 1275 |
| A4 | 440.00 | 2272 | 1136 |
@complexity O(n) where n = 42 notes @performance Takes ~10-15 seconds to complete (Q=250ms, H=500ms)
Array of notes for Twinkle Twinkle Little Star
Contains 42 note frequency values in sequence. Values correspond to C4, G4, A4, F4, E4, D4 from scale16.h.
Array of durations for Twinkle Twinkle Little Star
Each duration corresponds to the note at the same index in estrellita_notas[]. Uses Q (250ms) for short notes and H (500ms) for notes that should be held longer.
Play each note in sequence
Iterates through all 42 notes and plays each with its corresponding duration. The loop is blocking.
Definition at line 82 of file pre_defined_songs.c.
References A4, C4, D4, E4, F4, G4, H, playNote(), and Q.
Referenced by main().

