Site icon Making Studio

Ellen Does Arduino, Round II

Digital Input exercise:

 

Serial Monitor exercise:

 

I really wanted to figure out one of the more challenging prompts–to create an RGB mixer controlled by 3 buttons. I tried several times, to no avail.

 

And so here is the successful prompt–to turn an LED on/off with 2 separate buttons.

Here is the code for this operation:

const int buttonOn = 2;
const int buttonOff = 3;
const int ledPin = 13;


void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonOn, INPUT);
  pinMode(buttonOff, INPUT);

 

  // put your setup code here, to run once:

}

void loop() {   
  if (digitalRead(buttonOn) == LOW) {
    digitalWrite(ledPin, LOW); 
  }
  if (digitalRead(buttonOff) == LOW){
    digitalWrite(ledPin, HIGH);
  }
}
Exit mobile version