Homework 02 – RGB LED Blink with Potentiometer – Kevin Desautels

29 Oct

Image

For this assignment I tampered with the code so that instead of the lights blinking red-blue-green they blink in reverse order, too. With the new code it now blinks red-blue-green-blue-red. The amount of time in between each light goes on and off is determined manually with the potentiometer. The effect is pretty smooth and would be cooler if I had more LEDs.  

Code:

int red = 3; //sets red LED variable
int blue = 5; //sets blue LED variable
int green = 6; //sets green LED variable
int pot = 0; //sets potentiometer

void setup() {
pinMode (red, OUTPUT) ; //sets pin 3 to output
pinMode (blue, OUTPUT) ; //sets pin 5 to output
pinMode (green, OUTPUT) ; //sets pin 6 to output

}

void loop () {
pot = (analogRead (A0) ) ; //defines the pin the potentiometer is using
digitalWrite (red, HIGH) ; //turns on red LED
delay(pot) ; //allows the potentiometer to determine time interval manually
digitalWrite (red, LOW) ; //turns off red LED
delay(pot) ; //allows the potentiometer to determine time interval manually
digitalWrite (blue, HIGH) ; //turns on blue LED
delay(pot) ; //allows the potentiometer to determine time interval manually
digitalWrite (blue, LOW) ; //turns off blue LED
delay(pot) ; //allows the potentiometer to determine time interval manually
digitalWrite (green, HIGH) ; //turns on green LED
delay(pot) ; //allows the potentiometer to determine time interval manually
digitalWrite (green, LOW) ; //turns off green LED
delay(pot) ; //allows the potentiometer to determine time interval manually

digitalWrite (green, HIGH) ; //turns on green LED
delay(pot) ; //allows the potentiometer to determine time interval manually
digitalWrite (green, LOW) ; //turns off green LED
delay(pot) ; //allows the potentiometer to determine time interval manually
digitalWrite (blue, HIGH) ; //turns on blue LED
delay(pot) ; //allows the potentiometer to determine time interval manually
digitalWrite (blue, LOW) ; //turns off blue LED
delay(pot) ; //allows the potentiometer to determine time interval manually
digitalWrite (red, HIGH) ; //turns on red LED
delay(pot) ; //allows the potentiometer to determine time interval manually
digitalWrite (red, LOW) ; //turns off red LED
delay(pot) ; //allows the potentiometer to determine time interval manually

}

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