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);
  }
}

2 thoughts on “Ellen Does Arduino, Round II”

  1. Your code wants an analog sensor, in this case a potentiometer. It’s not the best example to base your sketch on… Try taking the RGB example from last week and adding some button code to it! You can do it! Also please post your successful two-button code, please!

    Like

  2. Hi Becky–thank you for the feedback! I just added the correct (successful) two-button code. Will dig deeper into the RGB-mixer script.

    Like

Comments are closed.