Problem 1: HW 5: RGB LED Expanded (associated Lab 3 RGB LED) Using the code in the RGB lab as a starting point, make the following modifications. Post the code and a video of it working in the homework submission. Homework: Modify your program to add the colors of Teal, Orange and White for a total of 7 colors and one off-state. Implement a switch statement to control the color mode instead of multiple if statements Add a second button that will toggle the blink mode delay between 0, 100 ms, 800 ms, and 6400 ms. Zero means no blinking.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

this is the code:

const int BLED=9; //Blue LED on Pin 9
const int GLED=10; //Green LED on Pin 10
const int RLED=11; //Red LED on Pin 11
const int Switch=2; //The Button is connected to pin 2
boolean lastSwitch = LOW; //Last Button State
boolean currentSwitch = LOW; //Current Button State
int ledMode = 0; //Cycle between LED states
boolean ledOn = false;
void setup()
{
pinMode (BLED, OUTPUT); //Set Blue LED as Output
pinMode (GLED, OUTPUT); //Set Green LED as Output
pinMode (RLED, OUTPUT); //Set Red LED as Output
pinMode (Switch, INPUT); //Set button as input (not required)}
}
/** LED Mode Selection Pass a number for the LED state and set it accordingly.*/
void setMode(int mode)
{
//RED
if (mode == 1)
{
digitalWrite(RLED, HIGH);
digitalWrite(GLED, LOW);
digitalWrite(BLED, LOW);
}
//GREEN
else if (mode == 2)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, HIGH);
digitalWrite(BLED, LOW);
}
//BLUE
else if (mode == 3)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, LOW);
digitalWrite(BLED, HIGH);
}
//PURPLE (RED+BLUE)
else if (mode == 4)
{
analogWrite(RLED, 127);
analogWrite(GLED, 0);
analogWrite(BLED, 127);
}
//OFF (mode = 0)
else
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, LOW);
digitalWrite(BLED, LOW);
}
}
boolean debounce (boolean last)
{
boolean current = digitalRead(Switch);
if (lastSwitch != current)
{
delay(5);
current = digitalRead(Switch);
}
return current;
}
void loop()
{
currentSwitch = debounce(lastSwitch); //read button state
if (lastSwitch == LOW && currentSwitch == HIGH) //if it was pressed...
{
ledMode++; //increment the LED value
}
lastSwitch = currentSwitch; //reset button value
//if you've cycled through the different options,
//reset the counter to 0
if (ledMode == 5) ledMode = 0;
setMode(ledMode); //change the LED state}
}

Problem 1: HW 5: RGB LED Expanded (associated Lab 3 RGB LED)
Using the code in the RGB lab as a starting point, make the following modifications. Post the code and a
video of it working in the homework submission.
Homework:
Modify your program to add the colors of Teal, Orange and White for a total of 7 colors and one
off-state.
Implement a switch statement to control the color mode instead of multiple if statements
Add a second button that will toggle the blink mode delay between 0, 100 ms, 800 ms, and 6400
ms. Zero means no blinking.
Transcribed Image Text:Problem 1: HW 5: RGB LED Expanded (associated Lab 3 RGB LED) Using the code in the RGB lab as a starting point, make the following modifications. Post the code and a video of it working in the homework submission. Homework: Modify your program to add the colors of Teal, Orange and White for a total of 7 colors and one off-state. Implement a switch statement to control the color mode instead of multiple if statements Add a second button that will toggle the blink mode delay between 0, 100 ms, 800 ms, and 6400 ms. Zero means no blinking.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY