Friday 20 November 2015

Lab 3 - Button Control

Purpose:
Use the button to turn on and off the LED

Equipment:
Push button (x 2)
Resistor
LED
Wires (x 6)

Program Details:
I used the program off newinnovators.ca

Time to Program and Complete:
5 minutes

Results:
N/A



Photo/Video Proof:



























Program:

const int buttonPin = 2;
//makes a variable called buttonPin hold a value of 2. Const makes the variable constant and unchanging
const int ledPin = 9;
//makes a variable called ledPin hold a value of 9. Const makes the variable constant and unchanging

int buttonState = 0;
//makes a variable called buttonState with a value of 0

void setup()
//the code underneath is isolated from the other code
{
//anything underneath is part of the above code
  pinMode(ledPin, OUTPUT);
//identifies the ledPin as either and output or input
  pinMode(buttonPin, INPUT);
//identifies the buttonPin as either and output or input
}

void loop()
//the code underneath will loop continuously
{
//beginning of loop function
  buttonState = digitalRead(buttonPin);
//checks to see if a variable is true
  if (buttonState == HIGH)
//if buttonState is equal to HIGH
  {
//beginning of loop
    digitalWrite(ledPin, HIGH);
//gives power to ledPin 
  }
//ends loop
  else
//if the original condition is not true do this:
  {
//beginning of loop
    digitalWrite(ledPin, LOW);
//gives LOW power to ledPin
  }
//end loop
}
//end loop

Program Modifications:
N/A

Helpful Tips:
make sure the wires lead to the right port

References:
newinnovators.ca

No comments:

Post a Comment