Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Edit the code give to write an Arduino code such that when you press the left bu

ID: 3605999 • Letter: E

Question

Edit the code give to write an Arduino code such that when you press the left button 3 times, Neopixel #0 will turn ON if it is OFF, and turn OFF if it is ON. The Neopixel can be any color:

#include <Adafruit_CircuitPlayground.h>

void setup() {
// Initialize the circuit playground
CircuitPlayground.begin();

CircuitPlayground.setBrightness(10);

}

void loop() {
bool buttonPress;

buttonPress = CircuitPlayground.leftButton();

if(buttonPress) {

CircuitPlayground.setPixelColor(0,255,255,255);

}

else {

CircuitPlayground.clearPixels();

}

}

Explanation / Answer

Solution====================

#include <Adafruit_CircuitPlayground.h>

int count=0; //Will count the number of times button is pressed
int shuffle=1; //Will shuffle between on and off

void setup() {
// Initialize the circuit playground
CircuitPlayground.begin();

CircuitPlayground.setBrightness(10);

}

void loop() {
bool buttonPress;

buttonPress = CircuitPlayground.leftButton();

if(buttonPress) count++; //Increment count value

//The moment count gets to be 3
if(count==3){
count =0; //Reset back

//Shuffle on or Off
if(shuffle==1){
   CircuitPlayground.setPixelColor(0,255,255,255);
   shuffle=0;
}else{
    CircuitPlayground.clearPixels();
    shuffle=1;
}

}

}

Let me know if any doubts...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote