Question: INTRODUCTION: In this week's tutorial you will partially implement a reaction - time game which will be controlled by the four pushbuttons on the QUTy.
INTRODUCTION:
In this week's tutorial you will partially implement a reactiontime
game which will be controlled by the four pushbuttons on the QUTy.
The program randomly produces one of four values which correspond to a
unique output from both the buzzer and segment display.
These outputs are described in the table below:
VALUE Buzzer frequency segment display
XY Segments EF LHS
XY Segments BC LHS
XY Segments EF RHS
XY Segments BC RHS
where XY are the last two digits of your student number.
The aim of this game is for the player to press the pushbutton
corresponding to these outputs, as quickly as possible.
To indicate that a pushbutton has been pressed by the player, the same
outputs will be produced.
void statemachinevoid;
int mainvoid
EX:
TASK: Implement the following functions:
"buzzeron and "buzzeroff" in "buzzer.c
"updateplaybackdelay" in "timer.c
cli;
adcinit;
buttoninit;
spiinit;
pwminit;
timerinit;
sei;
statemachine;
void enableoutputsuintt value
EX:
TASK: Implement the functions below to turn the buzzer ON and OFF.
The "buzzeron function should take a single argument, "tone", which
ranges from to and sets the frequency of the waveform output
generated by TCA correspondingly.
Ensure that the above macros reflect the four frequencies produced by
your program, given that TCA uses a DIV prescaler.
void buzzeronconst uintt tone
static const uintt baseperiodsTONEPER, TONEPER, TONEPER, TONEPER;
CODE: Write your code for Ex within this function.
uintt playbackdelay ;
void updateplaybackdelayvoid
EX:
To control the difficulty of this game, the player can use the
potentiometer to adjust the duration of the outputs produced by the
program.
TASK: Use ADC to update the "playbackdelay" variable based on the
position of the potentiometer. This value should be a linear
interpolation of the position of the potentiometer, ranging between
ms and ms
In "initialisation.c:adcinit", freerunning mode has been disabled
to improve program efficiency and reduce sampling inconsistency.
Due to this, we must manually start conversions when this function
is called and wait for them to complete.
Use the following steps to achieve this:
Start a conversion using the START group configuration in the
COMMAND register.
Wait for a conversion to complete before updating the playback
delay. See the Result Ready flag in the INTFLAGS register.
Upon reading the conversion result from the RESULT register,
clear the appropriate flag in the INTFLAGS register.
CODE: Write your code for Ex within this function.
EX:
To promote modularity, we can write a function that enables the
segment display and buzzer. The pattern and tone should correspond
to either the random number generated by the program, or the input
provided by the player.
TASK: Use the functions "updatedisplay" and "buzzeron to enable
the outputs of the game based on the value passed to this function.
The outputs produced by this function should correspond to the table
above.
NOTE: Several macros have been defined in "displaymacros.h to be
used as inputs to the "updatedisplay" function.
To ensure timing is correct and fair, update the playback delay
after all outputs have been enabled, and then reset the
"elapsedtime" variable.
CODE: Write your code for Ex within this function.
void disableoutputsvoid
EX:
TASK: Use the functions "updatedisplay" and "buzzeroff" to disable
the segment display and buzzer.
CODE: Write your code for Ex within this function.
typedef enum
GENERATE,
PROMPT,
INPUTWAITING,
INPUTRECEIVED,
INPUTEVALUATE,
DISPLAYSUCCESS,
DISPLAYFAILURE
statet;
void statemachinevoid
disableoutputs;
EX:
TASK: In the global scope we have declared an enumerated type enum
that holds the values of each state required to implement the state
machine in statemachinetutpng Declare and initialise a
variable of this type to store the initial state of the state
machine.
CODE: Write your code for Ex above this line.
EX:
A pseudorandom number generator PRNG has been implemented in
"tuto which is linked to this program. The function rng
can be called to generate a bit pseudorandom number.
TASK: Initialise a variable called "seed" with a value equal to your
student number in hexadecimal. Then, initialise the PRNG by calling
the "setseed" function.
CODE: Write your code for Ex above this line.
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
