Lab 4
Code for ECE 474 lab4
lab4rt2.ino File Reference

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...
 

Detailed Description

Code for Task RT-2.

Author
Fusco Li, Eric Yu
Date
10-June-2022

The program to use FreeRTOS library to play "Close Encounters" theme song

Macro Definition Documentation

◆ Note_C3

#define Note_C3   7692

130Hz frequency to play

◆ Note_C4

#define Note_C4   3830

261Hz frequency to play

◆ Note_D4

#define Note_D4   3400

294Hz frequeny to play

◆ Note_E4

#define Note_E4   3038

329Hz frequency to play

◆ Note_G3

#define Note_G3   5102

196Hz frequencys to play

◆ Note_R

#define Note_R   0

slience frequency

◆ REPEAT_TIMES

#define REPEAT_TIMES   3

Numbers of times to repeat the tune.

◆ SLEEP_DUR

#define SLEEP_DUR   3000UL

define sleep time

◆ SOUND_DUR

#define SOUND_DUR   500

define the duration for each note/sound the speaker play

Function Documentation

◆ loop()

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.

◆ setup()

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.

◆ TaskTheme()

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.

Parameters
pvParametersparameters that FreeRTOS can pass in

Variable Documentation

◆ melody

the "Close Encounter" tune going to play

◆ tuneLen

int tuneLen = sizeof(melody) / 2

define tune array length