Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

convert the following c + + code to AVR Assembly code: #include #include #include / / Pin Definitions #define START _ PAUSE _ BUTTON 1

convert the following c++ code to AVR Assembly code:
#include
#include
#include
// Pin Definitions
#define START_PAUSE_BUTTON 1
#define STOP_BUTTON 0
#define RGB_RED_PIN 2
#define RGB_GREEN_PIN 3
#define RGB_BLUE_PIN A0
const int ledPins[]={4,5,6,7,8,9,10,11,12,13};
const int numLeds =10;
const int numRounds =5;
const int ledOnTime =1500; // Milliseconds each LED is on
int currentLED =0;
int score =0;
int currentRound =0;
int indicatorLED;
bool gameRunning = false;
bool pauseGame = false;
int lastStartPauseButtonState = HIGH;
int lastStopButtonState = HIGH;
void setup(){
Serial.begin(9600);
for (int i =0; i < numLeds; i++){
pinMode(ledPins[i], OUTPUT);
}
pinMode(START_PAUSE_BUTTON, INPUT_PULLUP);
pinMode(STOP_BUTTON, INPUT_PULLUP);
pinMode(RGB_RED_PIN, OUTPUT);
pinMode(RGB_GREEN_PIN, OUTPUT);
pinMode(RGB_BLUE_PIN, OUTPUT);
}
void loop(){
int startButtonState = digitalRead(START_PAUSE_BUTTON);
int stopButtonState = digitalRead(STOP_BUTTON);
Serial.print("Start button state: ");
Serial.println(startButtonState);
Serial.print("Stop button state: ");
Serial.println(stopButtonState);
// Start/Pause the game
if (startButtonState == LOW && lastStartPauseButtonState == HIGH){
delay(50); // Debouncing
if (digitalRead(START_PAUSE_BUTTON)== LOW){// Check if still pressed
if (!gameRunning){
gameRunning = true;
currentRound =0;
score =0;
Serial.println("Game Started");
pickIndicatorLED();
} else {
pauseGame =!pauseGame;
Serial.println(pauseGame ? "Game Paused" : "Game Resumed");
}
}
}
lastStartPauseButtonState = startButtonState;
// Stop button logic
if (stopButtonState == LOW && lastStopButtonState == HIGH){
delay(50); // Debouncing
if (digitalRead(STOP_BUTTON)== LOW){// Check if still pressed
if (gameRunning && currentLED == indicatorLED){
score++;
Serial.print("Score: ");
Serial.println(score);
}
currentRound++;
if (currentRound < numRounds){
pickIndicatorLED();
} else {
gameRunning = false;
updateRGB(score);
Serial.println("Game Over");
}
}
}
lastStopButtonState = stopButtonState;
// Game logic when running and not paused
if (gameRunning && !pauseGame){
cycleLEDs();
}
}
void pickIndicatorLED(){
indicatorLED = random(0, numLeds);
Serial.print("Indicator LED: ");
Serial.println(indicatorLED);
}
void cycleLEDs(){
for (int i =0; i < numLeds; i++){
digitalWrite(ledPins[i], HIGH);
delay(ledOnTime);
digitalWrite(ledPins[i], LOW);
currentLED = i;
}
}
void updateRGB(int score){
digitalWrite(RGB_RED_PIN, LOW);
digitalWrite(RGB_GREEN_PIN, LOW);
digitalWrite(RGB_BLUE_PIN, LOW);
if (score >=4){
digitalWrite(RGB_GREEN_PIN, HIGH);
} else if (score >=2){
digitalWrite(RGB_BLUE_PIN, HIGH);
} else {
digitalWrite(RGB_RED_PIN, HIGH);
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions