A embedded system that can play monophonic music. Here`s a link to a video that demonstrates the project working.
Here are all components used in this project:
- Atmel SAM E70 XPLAINED (link)
- OLED1XPLAINEDpro (link)
- 1x BUZZER
- 2x JUMPERS (female-to-female or male-to-female)
- 1x PROTOBOARD (only necessary when jumpers are male-to-female)
The connection needs to be as the following:
After connecting the components, the cable must be plugged in the computer USB. To compile the program, the software used is Atmel Studio 7.0, so it needs to be opened in order to run the project.
Type | Action | Connection |
---|---|---|
Button 1 | Previous music | PIOD28 |
Button 2 | Play / Pause | PIOC31 |
Button 3 | Next Music | PIA19 |
Led 1 | Lower frequencies | PA0 |
Led 2 | Mid frequencies | PIOC30 |
Led 3 | Higher frequencies | PIOB2 |
Buzzer | Play frequency | PIOA3 / GND |
Screen | Displays music name | --------------- |
The code structure is expalined below:
// Files used by OLED display.
// Header file that define all OLED buttons, led and the buzzer PIO`s.
// Header file that define the music struct.
typedef struct {
...
} Song_to_play;
(all credits)
// Header file that define the musics frequencies and tempo`s.
int mario_main[]
int mario_main_tempo[]
int pirates_of_the_caribean[]
int pirates_of_the_caribean_tempo[]
int underworld_mario[]
int underworld_mario_tempo[]
// Header file that define all frequencies.
// Header file that define all initial configurations.
void create_songs() { ... } // Create all songs and transform them into structures for function passing
void init(void) { ... } // Clock init, create interruptions, set pio output and input
// Callbacks functions for interruption
void but_next_callback(void){ ... }
void but_prev_callback(void){ ... }
void but_play_callback(void){ ... }
// Header file that define all core and functional functions.
void pause() { ... } // Pause music
void oled_draw(char* string, int size) { ... } // Function that display the given string to oled with text centralization
void buzz(int frequency, int length, int max, int min) { ... } // Make the buzzer play the song frequency and control the LED`s.
void play(Song_to_play song) { ... } // Play the given song, call buzz() whenever a note needs to be played and pause() whenever the pause button is pressed
// Header file that includes all API header files for the selected drivers from ASF.
// Header file that includes all include_files/ and screen/ header file.
#include "include_files/*.h"
// c file that control wich core_functions are called, skip, play and return to previous music. Uses the init_functions to create songs and init pio clock
int main(void) {
init();
create_songs();
while (1) { ... } // Play, pause, draw, ...
}