Thursday, 3 December 2015

Arduino Lab 3 part 1

Purpose:
 Make an LED turn on and off using one button.

Equipment:
LED (Any Colour)
6 Wires(Any Colour)
3 Resistors
Push button

Program Details:
Arduino

Time to Program and Complete:
15mins

Results:
-what problems did you have and how did you fix it?

Photo/Video Proof:
none right now

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:
None

Helpful Tips:
None

References:
Aron Graca
Kyle Chan

No comments:

Post a Comment