Jimmy Huang
Created September 28, 2015

HW3: LED Exercises and Automata - 09/27/15

.

HW3: LED Exercises and Automata - 09/27/15

Things used in this project

Story

Read more

Schematics

Schematic.JPG

Code

Untitled file

C/C++
// Turn on LED while the button is pressed
// Massimo Banzi, from "Getting Started with Arduino"

const int LED = 13;   // the pin for the LED
const int BUTTON = 7; // the input pin where the
                      // pushbutton is connected
int val = 0;          // val will be used to store the state
                      // of the input pin

void setup() {
  pinMode(LED, OUTPUT);   // tell Arduino LED is an output
  pinMode(BUTTON, INPUT); // and BUTTON is an input
}

void loop(){
  val = digitalRead(BUTTON); // read input value and store it

  // check whether the input is HIGH (button pressed)
  if (val == HIGH) {
    digitalWrite(LED, HIGH); // turn LED ON
  } else {
    digitalWrite(LED, LOW);
  }
}

Credits

Jimmy Huang

Jimmy Huang

16 projects • 9 followers

Comments