Thursday, 3 December 2015

Arduino Lab 3 Part 2

Purpose:
 Use a second button so one turns it on, and the other turns it off.

Equipment:
Push button
330 Ohm resistor 
3 Led's (Any color)

Program Details:
Arduino

Time to Program and Complete:
10mins

Results:
No problems

Photo/Video Proof:
None right now

Program:
int led = 9; -This makes a variable called led which holds a value of 9
int onbutton = 3; -This makes a variable called onbutton which holds a value of 3
int offbutton = 2; -This makes a variable called offbutton which holds a value of 2

void setup () - void setup() is starting
{ - Start of void setup()
  pinMode(led, OUTPUT); -Declares led (pin 9) to be an Output
  pinMode(onbutton, INPUT); -Declares onbutton (pin 3) to be an input
  pinMode(offbutton, INPUT); -Declares offbutton (pin 2) to be an input
- End of void setup()

void loop () -void loop() is starting
{ -Start of void loop()
  if (digitalRead(offbutton) == LOW)
  { -Start of if statement
    digitalWrite(led, LOW);
  } - End of if statement
  else if (digitalRead (onbutton) == LOW)
  {-Start of else statement
    digitalWrite(led, HIGH);
  }-End of else statement
}-End of program
Program Modifications:
None

Helpful Tips:
List any suggestions to make this easier for new users

References:
Aron Graca
Kyle Chan

No comments:

Post a Comment