Arduino Week 3

Hi guys!

Below are the videos for my Arduino Week 3 work. This week’s stuff was tricky for me… not gonna lie. I feel that I am on the verge of a mental breakthrough with understanding how writing code works… but still trudging through the mental muck.

Digital Input

I got a little turned around with Becky’s mind games but both Digital inputs are here:

The Serial Monitor/Analog Input

Two Buttons Control one LED (on and off)

This was so tricky for me! But Tinker sphere was a great place to work it all through and I had some light adjustments when I built it out IRL, and the code isn’t too pretty but it’s working and that’s magic.

Screen Shot 2018-09-25 at 5.57.47 PM

/*
  Button

 Turns on and off a light emitting diode(LED) connected to digital
 pin 13, when pressing a pushbutton attached to pin 2.


 The circuit:
 * LED attached from pin 13 to ground
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground

 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.


 created 2005
 by DojoDave <http://www.0j0.org>
 modified 30 Aug 2011
 by Tom Igoe

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/Button
 */

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
const int buttonPinoff = 7;  //the number of pushbutton2 pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int buttonState2 =0;    // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(buttonPinoff, INPUT_PULLUP);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  buttonState2 = digitalRead(buttonPinoff);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == LOW) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  }
  // check if the pushbutton2 is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState2 == LOW) {
    // turn LED on:
    digitalWrite(ledPin, LOW);}
}

 

One thought on “Arduino Week 3”

  1. Whoohoo that looks great! Especially love that you worked it out in Tinkercad, would you mind sharing the URL to your public circuit so other folks can check it out? Thanks!

    Like

Comments are closed.