Image

Homework 02 – RGB LED blink with Potentiometer – Arthur Dunne

28 Oct

Assignment 02 - RGB LED blink with Potentiometer - Arthur Dunne

I used the Arduino to create a blinking pattern with the red blue and green LEDs. The pattern starts on the red, then goes to blue and stays for two on and offs, then goes to green. Even with a simple variation in just one of the LEDs, the effect is very different with every change in the potentiometer.

Here’s my code:

int red = 3; // setting red led variable
int blue = 5; // setting blue led variable
int green = 6; // setting green led variable
int pot = 0; // potentiometer

void setup() {
pinMode(red, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(green, OUTPUT);
}

void loop() {
pot = (analogRead (A0));
digitalWrite(red, HIGH); //turn red light on
delay(pot); //holds red light on for a certain amount of time based on what position the potentiometer is at
digitalWrite(red, LOW); //turns red light off
delay(pot); //holds red light off for a certain amount of time based on what position the potentiometer is at
digitalWrite(blue, HIGH); //turns blue light on
delay(pot); //holds blue light on for a certain amount of time based on what position the potentiometer is at
digitalWrite(blue, LOW); //turns blue light off
delay(pot);//holds blue light off for a certain amount of time based on what position the potentiometer is at
digitalWrite(blue, HIGH);//turns blue light on
delay(pot); //holds blue light on for a certain amount of time based on what position the potentiometer is at
digitalWrite(blue, LOW); //turns blue light off
delay(pot); //holds blue light off for a certain amount of time based on what position the potentiometer is at
digitalWrite(green, HIGH); //turns green light on
delay(pot); //holds green light on for a certain amount of time based on what position the potentiometer is at
digitalWrite(green, LOW); //turns green light off
delay(pot); //holds green light off for a certain amount of time based on what position the potentiometer is at
}

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