![]() |
Lab 4
Code for ECE 474 lab4
|
Code for Task RT-2. More...
#include <Arduino_FreeRTOS.h>
Macros | |
#define | Note_D4 3400 |
294Hz frequeny to play More... | |
#define | Note_E4 3038 |
329Hz frequency to play More... | |
#define | Note_C4 3830 |
261Hz frequency to play More... | |
#define | Note_C3 7692 |
130Hz frequency to play More... | |
#define | Note_G3 5102 |
196Hz frequencys to play More... | |
#define | Note_R 0 |
slience frequency More... | |
#define | SOUND_DUR 500 |
define the duration for each note/sound the speaker play More... | |
#define | SLEEP_DUR 3000UL |
define sleep time More... | |
#define | REPEAT_TIMES 3 |
Numbers of times to repeat the tune. More... | |
Functions | |
void | TaskTheme (void *pvParameters) |
Play "Close Encounters" on an external speaker Three times. More... | |
void | setup () |
Funciton to setup RtOS tasks. More... | |
void | loop () |
loop though different funcitons, not in use for this lab More... | |
Variables | |
int | melody [] = { Note_D4, Note_R, Note_E4, Note_R, Note_C4, Note_R, Note_C3, Note_R, Note_G3, Note_R } |
the "Close Encounter" tune going to play More... | |
int | tuneLen = sizeof(melody) / 2 |
define tune array length More... | |
Code for Task RT-2.
The program to use FreeRTOS library to play "Close Encounters" theme song
#define Note_C3 7692 |
130Hz frequency to play
#define Note_C4 3830 |
261Hz frequency to play
#define Note_D4 3400 |
294Hz frequeny to play
#define Note_E4 3038 |
329Hz frequency to play
#define Note_G3 5102 |
196Hz frequencys to play
#define Note_R 0 |
slience frequency
#define REPEAT_TIMES 3 |
Numbers of times to repeat the tune.
#define SLEEP_DUR 3000UL |
define sleep time
#define SOUND_DUR 500 |
define the duration for each note/sound the speaker play
void loop | ( | ) |
loop though different funcitons, not in use for this lab
This program uses RTOS so this function is not in use. Things are done in Tasks.
void setup | ( | ) |
Funciton to setup RtOS tasks.
Setup serial communication method and creat RTOS tasks. Set the priority of each task as well as its size.
void TaskTheme | ( | void * | pvParameters | ) |
Play "Close Encounters" on an external speaker Three times.
First it setup the registers and timers for the speaker. Then loop thought the task three times. Within the loop there is another for loop that increment through melody
array to use the correct note freqencies to play sounds. Use vTaskDelay
to wait in between notes and songs. Use vTaskSuspend
to stop the task.
pvParameters | parameters that FreeRTOS can pass in |
int melody[] = { Note_D4, Note_R, Note_E4, Note_R, Note_C4, Note_R, Note_C3, Note_R, Note_G3, Note_R } |
the "Close Encounter" tune going to play
int tuneLen = sizeof(melody) / 2 |
define tune array length