Question: I ' m having trouble with my code currently. the code needs to split a playback delay so the display and buzzer are on for
Im having trouble with my code currently. the code needs to split a "playback delay" so the display and buzzer are on for half and then blank and silent for the other half currently this is what i have: test results at the bottom
void delayfunctionint percentage
Ensure percentage is nonzero and valid
if percentage
return; Avoid unnecessary delays if percentage is
Calculate the base delay as a function of the potentiometer input, scaled between and seconds
potentiometervalue ADCRESULT; Read the potentiometer input
scaledvalue floatpotentiometervalue ; Scale to seconds
Adjust the delay using the percentage value
clockdelay scaledvalue percentage; Calculate clock cycles required for the delay
Delay loop
for volatile uintt i ; i clockdelay; i
No operation NOP
void playbacksequenceuintt sequencevalues int sequencelength
for uintt i ; i sequencelength && sequencestatus ; i
playsequencestepsequencevaluesi; Play each step set display and buzzer
Active buzzer and display for of the duration ms equivalent
delayfunction; Use percentage for half of the playback duration with tone and display active
Turn off both the buzzer and the display after ms
TCASINGLE.PER ; Turn off the buzzer
TCASINGLE.CMP; Set the duty cycle to silence
spitransmitdisplaybuffer SEGMENTOFF; Transmit the off state for the first display segment
spitransmitdisplaybuffer SEGMENTOFF; Transmit the off state for the second display segment
Delay for the remaining of the duration inactive period
delayfunction; Use percentage for half of the playback duration with tone and display off
sequencestatus ; Sequence is done
void handlevalueuintt displayone, uintt displaytwo, int tone
spitransmitdisplaybuffer displayone; Set and transmit the first display value
spitransmitdisplaybuffer displaytwo; Set and transmit the second display value
TCASINGLE.PER tone; Set the tone frequency
TCASINGLE.CMPtone ; Set the duty cycle for the tone
void playsequencestepuintt stepvalue
Handle tone and display for the active phase
if stepvalue
handlevalueSEGMENT SEGMENTOFF, TONEPER; Play tone and display
else if stepvalue
handlevalueSEGMENT SEGMENTOFF, TONEPER; Play tone and display
else if stepvalue
handlevalueSEGMENTOFF, SEGMENT TONEPER; Play tone and display
else if stepvalue
handlevalueSEGMENTOFF, SEGMENT TONEPER; Play tone and display
test results:
Gameplay events: ms: S ms: S ms: S ms: S ms: S Detected buzzer events: ms: Hz duty cycle ms: Hz duty cycle Detected display events: ms: ms: ms: ms: ms: ms: ms: ms: ms: ms: EVENT SimonPLAYBACK DELAY: ms FAIL. Buzzer did not turn OFF after ms FAIL. Display produced too late. Correct output was detected ms after program start. Further testing requires all tests to pass.
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
