Question
Arduino Uno Code: int redOn = HIGH; int greenOn = HIGH; void setup() { pinMode(2, OUTPUT); pinMode(4, OUTPUT); digitalWrite(2, redOn); digitalWrite(4, greenOn); Serial.begin(9600); } void
Arduino Uno Code:
int redOn = HIGH; int greenOn = HIGH; void setup() { pinMode(2, OUTPUT); pinMode(4, OUTPUT); digitalWrite(2, redOn); digitalWrite(4, greenOn); Serial.begin(9600); } void loop() { delay(10); // Delay a little bit to improve simulation performance digitalWrite(2, redOn); digitalWrite(4, greenOn);
if(Serial.available()){ char c = Serial.read(); if (c == 'r'){ if (redOn == HIGH){ redOn = LOW; Serial.println("Red LED Off"); } else{ redOn = HIGH; Serial.println("Red LED On"); } } if (c == 'g'){ if (greenOn == HIGH){ greenOn = LOW; Serial.println("Green LED Off"); } else{ greenOn = HIGH;
Serial.println("Green LED On"); } } } }
Question:
Based on the code provided, add the following three functions to the circuit:
- If a is typed into the serial monitor, both LEDs turn on and the message All LEDs On is displayed.
- If o is typed into the serial monitor, both LEDs turn off and the message All LEDs Off is displayed.
- If a character other than r, g, a or o is typed into the serial monitor, the message Unknown Command is displayed.
Please provide Arduino code! Thanks!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started