Question: INTRODUCTION: In this week's tutorial you will extend the functionality of the reaction - time game you built in Tutorial 1 1 . Before attempting
INTRODUCTION:
In this week's tutorial you will extend the functionality of the
reactiontime game you built in Tutorial
Before attempting the tasks below, copy the contents of the following
files from your finished Tutorial project:
srcbuzzerc
srctimerc
srctutorialc this file
This week you will implement the following commands that will be
transmitted via UART:
S: via
S: via
S: via
S: via
INCFREQ: via
DECFREQ: via
void statemachinevoid;
int mainvoid
cli;
adcinit;
buttoninit;
spiinit;
pwminit;
timerinit;
uartinit;
sei;
statemachine;
void enableoutputsuintt value
void disableoutputsvoid
typedef enum
GENERATE,
PROMPT,
INPUTWAITING,
INPUTRECEIVED,
INPUTEVALUATE,
DISPLAYSUCCESS,
DISPLAYFAILURE
statet;
void statemachinevoid
disableoutputs;
Player input
uintt input ;
Player reaction time
uintt reactiontime ;
Pushbutton state
uintt pbpreviousstate, pbcurrentstate xFF;
Pushbutton edge flags
uintt pbfallingedge, pbrisingedge x;
while
EX:
There is no simple mechanism to measure the duration of a
keypress when receiving UART inputs S to S Therefore, when
providing feedback for inputs S to Svia the pushbuttons or
UART ensure that the corresponding outputs are enabled for at
least the playback delay.
TASK: Extend the state machine you built in Tutorial to
accept alternative inputs via UART.
The gameplay commands S to S correspond to pushbutton inputs
S to S respectively. Use the variable "uartinput" from
"uart.c to access the current UART input command.
When no UART inputs are received or after a UART input has been
processed, you should set "uartinput" to
CODE: Write your code for Ex within this while loop.
Values used to write to the TCASINGLE.PERBUF register.
#define TONEPER
#define TONEPER
#define TONEPER
#define TONEPER
static uintt selectedtone ;
static intt octave ;
EX:
TASK: Declare a static global Boolean variable "buzzerplaying" to allow
the buzzer frequency to be updated while the buzzer is playing.
CODE: Write your code for Ex above this line.
EX:
TASK: Extend the "buzzeron and "buzzeroff" functions to modify the
variables "buzzerplaying" and "selectedtone".
Also, update the logic in the "buzzeron function to adjust the
frequency of the buzzer output based on the static global variable
"octave".
HINT: An octave is a doubling or halving of frequencies, and frequency
is inversely proportional to period.
void buzzeronconst uintt tone
static const uintt baseperiodsTONEPER, TONEPER, TONEPER, TONEPER;
void buzzeroffvoid
EX:
TASK: Implement the functions "increaseoctave" and "decreaseoctave"
to modify the static global variable "octave". If the buzzer is playing,
these functions should also update the buzzer frequency accordingly.
The octave should be limited to the range to
void increaseoctavevoid
CODE: Write your code for Ex within this function.
void decreaseoctavevoid
CODE: Write your code for Ex within this function.
EX:
TASK: Declare a variable "uartinput" to store the current UART input to
the reactiontime game. This variable will be used by both the main
state machine and the UART receive interrupt. Make sure to add this
variable to the header file "uart.h
When no input is received, the variable should be set to
CODE: Write your code for Ex above this line.
ISRUSARTRXCvect
EX:
TASK: Handle the following serial commands as they are received via
UART:
Characters to should modify the variable "uartinput" to
corresponding numeric values to be used by the main state machine.
The character should increase the octave of the frequencies
produced by the buzzer.
The character should decrease the octave of the frequencies
produced by the buzzer.
CODE: Write your code for Ex within this function.
Read received data and clear interrupt flag
char rxdata USARTRXDATAL;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
