Question: This task is to create a Simon says game on the ATtiny 1 6 2 6 and this is the code so far main.c #include

This task is to create a Simon says game on the ATtiny1626 and this is the code so far
main.c
#include
#include "timer.h"
#include "spi.h"
#include "buzzer.h"
#include
// Constants
#define S1_STEP 0
#define S2_STEP 1
#define S3_STEP 2
#define S4_STEP 3
#define SEGS_EF 0b00111110
#define SEGS_BC 0b01101011
#define SEGS_OFF 0b01111111
// Variables volatile uint8_t segs[]={SEGS_OFF, SEGS_OFF}; // segs initially off volatile uint8_t pb_previous_state =0xFF; volatile uint8_t pb_new_state =0xFF;
volatile uint8_t pb_debounced =0xFF; // Define pb_debounced variable static uint8_t vcount0=0, vcount1=0; // Simon game variables uint8_t sequence[100];
// Array to store the sequence uint16_t sequenceLength =1;
// Initial sequence length uint16_t currentStep =0;
// Current step in the sequence uint16_t userSequence =0; uint8_t score =0;
typedef enum { WAIT, TONE1, TONE2, TONE3, TONE4} state_t;
// Functions void pb_init(void); void pb_debounce(void); void generateSimonSequence(void);
void pb_init(void){
// Already configured as inputs /
/ PBs PA4-7, enable pull-up resistors
PORTA.PIN4CTRL = PORT_PULLUPEN_bm;
PORTA.PIN5CTRL = PORT_PULLUPEN_bm;
PORTA.PIN6CTRL = PORT_PULLUPEN_bm;
PORTA.PIN7CTRL = PORT_PULLUPEN_bm; }
void pb_debounce(void){/
/ Write your code for Ex 12.4 here
uint8_t pb_sample =(~PORTA.IN) & 0xF0;
uint8_t pb_changed = pb_sample ^ pb_debounced;
// Vertical counter update vcount1=(vcount1^ vcount0) & pb_changed; vcount0= ~vcount0 & pb_changed; pb_debounced ^= vcount0 & vcount1;
// Write your code for Ex 12.4 above this line }
// Function to read the potentiometer value and calculate the playback delay
// Code to read the potentiometer value and calculate the playback delay
// Function to get the user's input sequence void getUserInput(){ for (int i =0; i sequenceLength; i++){
// Code to get user input for each element in the sequence
// Store the input in user_sequence[i]}}
// Function to play the sequence of tones and light up corresponding segments void playSequence(){}
// Function to display the success pattern on the 7-segment display void displaySuccess(){
// Code to display the success pattern on the 7-segment display }
// Function to display the fail pattern on the 7-segment display void displayFail(){
// Code to display the fail pattern on the 7-segment display }
// Function to increase the sequence length and score void increaseSequenceLength(){ sequenceLength++; score = sequenceLength; }
// Function to reset the game void resetGame(){ sequenceLength =1; score =0; }
// Function to update score void update_score(void){
// Code to update the score score++; }
// Function to display the high scores table void displayHighScores(){
// Code to display the high scores table
// High scores struct HighScore { char name[21]; uint16_t score; }; struct HighScore highScores[]={{"Alice",20},{"Bob",18},{"Charlie",14},{"David",9},{"Erin",7}}; }
void reset_game(void){// Code to reset necessary variables and states for restarting the game currentStep =0; sequenceLength =1; score =0;
// Generate the initial sequence
// Other necessary reset actions }
void generateSimonSequence(void){ uint32_t lfsr =0x12312312; // uint32_t bit, step; for (uint16_t i =0; i sequenceLength; i++){ bit = lfsr & 1; lfsr >>=1; if (bit ==1){ lfsr ^=0xE2023CAB; } step = lfsr & 0b11; sequence[i]= step; // Update lfsr to generate the next step lfsr >>=2; lfsr |= bit 30; }}
// Function to start a new game void startGame(){ resetGame(); generateSimonSequence();
playSequence();
getUserInput();
displayHighScores(); }
int main(void){ pb_init(); timer_init(); spi_init(); buzzer_init(); buzzer_stop();
state_t state = WAIT;
while (1){ pb_debounce();
// Detect rising and falling edges uint8_t pb_falling =(pb_previous_state ^ pb_new_state) & pb_new_state;
uint8_t pb_rising =(pb_previous_state ^ pb_new_state) & pb_previous_state; switch (state){ case WAIT: if (pb_falling & PIN4_bm){ state = TONE1; buzzer_play(TONE1); segs[0]= SEGS_EF; segs[1]= SEGS_OFF; TCA0.SINGLE.PERBUF = TONE1_PER; TCA0.SINGLE.CMP0BUF = TONE1_PER >>1; } else if (pb_falling & PIN5_bm)
{ state = TONE2;
This task is to create a Simon says game on the

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!