Video

Homework 02 – Arduino Code LED Light – Daniel Scott

29 Oct

I liked the idea of trying to manually match the speed of the potentiometer with the timed light. The following is the code I used:

//attempt to do class assignment 10/28/2013

int red = 2; //setting red led variable
int blue = 5; //setting blue led variable
int green = 6; //setting green led variable
int pot = 0; //sets potentiometer pin number to A0

void setup() {
pinMode(red, OUTPUT); //sets the number of the pin as output
pinMode(blue, OUTPUT); //sets the number of the pin as output
pinMode(green, OUTPUT);//”sets the number of the pin as output”
}

void loop () {
pot = (analogRead(A0)); //potentiometer controls red and blue light
digitalWrite(red, HIGH); //light on
delay(pot); //potentiometer controls light on time
digitalWrite(red, LOW); //light off
delay(pot); //potentiometer controls light off time
digitalWrite(blue, HIGH); //light on
delay(pot); //potentiometer controls light on time
digitalWrite(blue, LOW); //light off
delay(pot); //potentiometer controls light off time
digitalWrite(green, HIGH); //light on
delay(500); //timer for light on
digitalWrite(green, LOW);//light off
delay(200); //timer for light off
}//loop back to beginning

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s