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 ATtiny and this is the code so far
main.c
#include
#include "timer.h
#include "spi.h
#include "buzzer.h
#include
Constants
#define SSTEP
#define SSTEP
#define SSTEP
#define SSTEP
#define SEGSEF b
#define SEGSBC b
#define SEGSOFF b
Variables volatile uintt segsSEGSOFF, SEGSOFF; segs initially off volatile uintt pbpreviousstate xFF; volatile uintt pbnewstate xFF;
volatile uintt pbdebounced xFF; Define pbdebounced variable static uintt vcount vcount; Simon game variables uintt sequence;
Array to store the sequence uintt sequenceLength ;
Initial sequence length uintt currentStep ;
Current step in the sequence uintt userSequence ; uintt score ;
typedef enum WAIT, TONE TONE TONE TONE statet;
Functions void pbinitvoid; void pbdebouncevoid; void generateSimonSequencevoid;
void pbinitvoid
Already configured as inputs
PBs PA enable pullup resistors
PORTA.PINCTRL PORTPULLUPENbm;
PORTA.PINCTRL PORTPULLUPENbm;
PORTA.PINCTRL PORTPULLUPENbm;
PORTA.PINCTRL PORTPULLUPENbm;
void pbdebouncevoid
Write your code for Ex here
uintt pbsample ~PORTA.IN & xF;
uintt pbchanged pbsample pbdebounced;
Vertical counter update vcountvcount vcount & pbchanged; vcount ~vcount & pbchanged; pbdebounced vcount & vcount;
Write your code for Ex 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 ; i sequenceLength; i
Code to get user input for each element in the sequence
Store the input in usersequencei
Function to play the sequence of tones and light up corresponding segments void playSequence
Function to display the success pattern on the segment display void displaySuccess
Code to display the success pattern on the segment display
Function to display the fail pattern on the segment display void displayFail
Code to display the fail pattern on the segment display
Function to increase the sequence length and score void increaseSequenceLength sequenceLength; score sequenceLength;
Function to reset the game void resetGame sequenceLength ; score ;
Function to update score void updatescorevoid
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; uintt score; ; struct HighScore highScoresAliceBobCharlieDavidErin;
void resetgamevoid Code to reset necessary variables and states for restarting the game currentStep ; sequenceLength ; score ;
Generate the initial sequence
Other necessary reset actions
void generateSimonSequencevoid uintt lfsr x; uintt bit, step; for uintt i ; i sequenceLength; i bit lfsr & ; lfsr ; if bit lfsr xECAB; step lfsr & b; sequencei step; Update lfsr to generate the next step lfsr ; lfsr bit ;
Function to start a new game void startGame resetGame; generateSimonSequence;
playSequence;
getUserInput;
displayHighScores;
int mainvoid pbinit; timerinit; spiinit; buzzerinit; buzzerstop;
statet state WAIT;
while pbdebounce;
Detect rising and falling edges uintt pbfalling pbpreviousstate pbnewstate & pbnewstate;
uintt pbrising pbpreviousstate pbnewstate & pbpreviousstate; switch state case WAIT: if pbfalling & PINbm state TONE; buzzerplayTONE; segs SEGSEF; segs SEGSOFF; TCASINGLE.PERBUF TONEPER; TCASINGLE.CMPBUF TONEPER ; else if pbfalling & PINbm
state TONE;
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
