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 reaction-time
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 7-segment display.
These outputs are described in the table below:
VALUE | Buzzer frequency |7-segment display
------|------------------|------------------
0|4XY *2^(-5/12)| Segments EF (LHS)
1|4XY *2^(-8/12)| Segments BC (LHS)
2|4XY | Segments EF (RHS)
3|4XY *2^(-17/12)| 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 state_machine(void);
int main(void)
{
/** EX: 11.0
TASK: Implement the following functions:
- "buzzer_on" and "buzzer_off" in "buzzer.c".
- "update_playback_delay" in "timer.c".
*/
cli();
adc_init();
button_init();
spi_init();
pwm_init();
timer_init();
sei();
state_machine();
}
void enable_outputs(uint8_t value)
/** EX: 11.0.1
TASK: Implement the functions below to turn the buzzer ON and OFF.
The "buzzer_on" function should take a single argument, "tone", which
ranges from 0 to 3, and sets the frequency of the waveform output
generated by TCA0 correspondingly.
Ensure that the above macros reflect the four frequencies produced by
your program, given that TCA0 uses a DIV2 prescaler.
*/
void buzzer_on(const uint8_t tone)
{
static const uint16_t base_periods[4]={TONE1_PER, TONE2_PER, TONE3_PER, TONE4_PER};
/** CODE: Write your code for Ex 11.0.1 within this function. */
uint16_t playback_delay =100;
void update_playback_delay(void)
{
/** EX: 11.0.2
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 ADC0 to update the "playback_delay" variable based on the
position of the potentiometer. This value should be a linear
interpolation of the position of the potentiometer, ranging between
100 ms and 500 ms.
In "initialisation.c:adc_init", free-running 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:
1. Start a conversion using the START group configuration in the
COMMAND register.
2. Wait for a conversion to complete before updating the playback
delay. See the Result Ready flag in the INTFLAGS register.
3. Upon reading the conversion result from the RESULT register,
clear the appropriate flag in the INTFLAGS register.
*/
/** CODE: Write your code for Ex 11.0.2 within this function. */
}
/** EX: 11.1.1
To promote modularity, we can write a function that enables the
7-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 "update_display" and "buzzer_on" 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 "display_macros.h" to be
used as inputs to the "update_display" function.
To ensure timing is correct and fair, update the playback delay
after all outputs have been enabled, and then reset the
"elapsed_time" variable.
*/
/** CODE: Write your code for Ex 11.1.1 within this function. */
}
void disable_outputs(void)/**
EX: 11.1.2
TASK: Use the functions "update_display" and "buzzer_off" to disable
the 7-segment display and buzzer.
*/
/** CODE: Write your code for Ex 11.1.2 within this function. */
}
typedef enum
{
GENERATE,
PROMPT,
INPUT_WAITING,
INPUT_RECEIVED,
INPUT_EVALUATE,
DISPLAY_SUCCESS,
DISPLAY_FAILURE
} state_t;
void state_machine(void)
{
disable_outputs();
/** EX: 11.2
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 state_machine_tut11.png. Declare and initialise a
variable of this type to store the initial state of the state
machine.
*/
/** CODE: Write your code for Ex 11.2 above this line. */
/** EX: 11.3
A pseudo-random number generator (PRNG) has been implemented in
"tut11_12.o", which is linked to this program. The function "rng"
can be called to generate a 32-bit pseudo-random number.
TASK: Initialise a variable called "seed" with a value equal to your
student number in hexadecimal. Then, initialise the PRNG by calling
the "set_seed" function.
*/
/** CODE: Write your code for Ex 11.3 above this line. */

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!