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
reaction-time game you built in Tutorial 11.
Before attempting the tasks below, copy the contents of the following
files from your finished Tutorial 11 project:
- src/buzzer.c
- src/timer.c
- src/tutorial11.c (this file)
This week you will implement the following commands that will be
transmitted via UART:
- S1: via '1'
- S2: via '2'
- S3: via '3'
- S4: via '4'
- INC_FREQ: via '.'
- DEC_FREQ: via ','
*/
void state_machine(void);
int main(void)
{
cli();
adc_init();
button_init();
spi_init();
pwm_init();
timer_init();
uart_init();
sei();
state_machine();
}
void enable_outputs(uint8_t value)
{
}
void disable_outputs(void)
{
}
typedef enum
{
GENERATE,
PROMPT,
INPUT_WAITING,
INPUT_RECEIVED,
INPUT_EVALUATE,
DISPLAY_SUCCESS,
DISPLAY_FAILURE
} state_t;
void state_machine(void)
{
disable_outputs();
// Player input
uint8_t input =0;
// Player reaction time
uint16_t reaction_time =0;
// Pushbutton state
uint8_t pb_previous_state, pb_current_state =0xFF;
// Pushbutton edge flags
uint8_t pb_falling_edge, pb_rising_edge =0x00;
while (1)
{
/** EX: 12.0
There is no simple mechanism to measure the duration of a
keypress when receiving UART inputs S1 to S4. Therefore, when
providing feedback for inputs S1 to S4(via 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 11 to
accept alternative inputs via UART.
The gameplay commands S1 to S4 correspond to pushbutton inputs
S1 to S4, respectively. Use the variable "uart_input" 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 "uart_input" to 4.
*/
/** CODE: Write your code for Ex 12.0 within this while loop. */
// Values used to write to the TCA0.SINGLE.PERBUF register.
#define TONE1_PER 0
#define TONE2_PER 0
#define TONE3_PER 0
#define TONE4_PER 0
static uint8_t selected_tone =0;
static int8_t octave =0;
/** EX: 12.1.1
TASK: Declare a static global Boolean variable "buzzer_playing" to allow
the buzzer frequency to be updated while the buzzer is playing.
*/
/** CODE: Write your code for Ex 12.1.1 above this line. */
/** EX: 12.1.2
TASK: Extend the "buzzer_on" and "buzzer_off" functions to modify the
variables "buzzer_playing" and "selected_tone".
Also, update the logic in the "buzzer_on" 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 buzzer_on(const uint8_t tone)
{
static const uint16_t base_periods[4]={TONE1_PER, TONE2_PER, TONE3_PER, TONE4_PER};
}
void buzzer_off(void)
{
}
/** EX: 12.1.3
TASK: Implement the functions "increase_octave" and "decrease_octave"
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 -2 to 2.
*/
void increase_octave(void)
{
/** CODE: Write your code for Ex 12.1.3 within this function. */
}
void decrease_octave(void)
{
/** CODE: Write your code for Ex 12.1.3 within this function. */
}
/** EX: 12.2.1
TASK: Declare a variable "uart_input" to store the current UART input to
the reaction-time 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 4.
*/
/** CODE: Write your code for Ex 12.2.1 above this line. */
ISR(USART0_RXC_vect)
{
/** EX: 12.2.2
TASK: Handle the following serial commands as they are received via
UART:
- Characters '1' to '4' should modify the variable "uart_input" 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 12.2.2 within this function. */
// Read received data and clear interrupt flag
char rx_data = USART0.RXDATAL;
}

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!