Question: This lab I need to be able to get my Arduino Uno to do 3 THINGS. So far I have only been able to complete
This lab I need to be able to get my Arduino Uno to do 3 THINGS. So far I have only been able to complete #1. When I upload my sketch the LED will cycle through 5 levels of brightness. I need help with the sketch for #2 and #3. Please review my sketch. It is Arduino
Procedure:
Design a circuit and Arduino program that accomplishes the following:
1. Reads a press of a pushbutton once, and it cycles through all possible brightness values
2. A press of the pushbutton a second time during the cycle, and it will reset the system by turning the LED off and setting the brightness value back to 0
3. Another press of the pushbutton again, and it will then start the brightness cycle over again.
MY SKETCH:
int switchPin = 8; int ledPin = 6; int ledLevel = 0; boolean lastButton = LOW; boolean currentButton = LOW; void setup() { pinMode(switchPin, INPUT); pinMode(ledPin, OUTPUT); }
boolean debounce(boolean last) { boolean current = digitalRead(switchPin); if(last != current) { delay(5); current = digitalRead(switchPin); } return current; }
void loop() { currentButton = debounce(lastButton); if(lastButton == LOW && currentButton <= HIGH) { ledLevel = ledLevel + 51; } if(ledLevel > 255) ledLevel = 0; analogWrite(ledPin, ledLevel); delay(500); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
