DESCRIPTION
In this lab, I soldered wires to potentiometers (pots) then setup my circuit/code to control one LED's brightness with a pot. Using a different code and the same circuit setup, I could control one LED's blinking rate with a pot. Next I modified my circuit to include 2 pots and used the code provided to control blinking rate and brightness independently with different pots.
For the homework, I first modified my code to have one pot control the brightness of all 3 LEDs together and one pot control the blinking rate of all 3 LEDs together (first code listed). Then, I modified the code so that the first pot still controlled the uniform brightness of the LEDs, but the second pot controlled the alternating blinking rate between the 3 LEDs. The code/LEDs are setup to blink in a line (green, red, blue, green, etc.) so they can "chase" each other with the chasing speed controlled by the second pot.
COMPONENTS USED
1- Arduino Uno (and USB cable/laptop)
3- LEDs (RGB)
3- 220Ω Resistors
1- Breadboard
2- 10kΩ Potentiometers
22 gauge wire
CODE #1: UNIFORMLY BLINKING LEDS
/*
* one pot dims, the other pot changes the blinking rate of the 3 LEDs blinking in unison
* modification of the following
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int pot1Pin = A0; // select the input pin for the potentiometer 1
int pot2Pin = A1; // select the input pin for the potentiometer 2
int pot1Val = 0; // variable to store the value coming from pot 1
int pot2Val = 0; // variable to store the value coming from pot 2
int led1Pin = 9; // select the pin for the LED 1
int led2Pin = 10; // select the pin for the LED 2
int led3Pin = 11; //select the pin for the LED 3
void setup() {
pinMode(led1Pin, OUTPUT); // declare the led1Pin as an OUTPUT
pinMode(led2Pin, OUTPUT); // declare the led2Pin as an OUTPUT
}
//code for uniform blinking LEDs
void loop() {
pot1Val = analogRead(pot1Pin); // read the value from pot 1, between 0 - 1024, for dimming
pot2Val = analogRead(pot2Pin); // read the value from pot 2, between 0 - 1024, for blinking
analogWrite(led1Pin, pot1Val/4); // dim LED to value from pot1
analogWrite(led2Pin, pot1Val/4);
analogWrite(led3Pin, pot1Val/4);
delay(pot2Val);
// stop the program for some time, meaning, LED is on for this time
analogWrite(led1Pin, 0); // dim LED to completely dark (zero)
analogWrite(led2Pin, 0);
analogWrite(led3Pin, 0);
delay(pot2Val); // stop the program for some time, meaning, LED is OFF for this time
}
CODE #2: "CHASING LEDS"
/*
* one pot controls brightness, the other pot changes the alternating blinking rate of 3 LEDs so they are "chasing" each other
* modification of the following
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int pot1Pin = A0; // select the input pin for the potentiometer 1
int pot2Pin = A1; // select the input pin for the potentiometer 2
int pot1Val = 0; // variable to store the value coming from pot 1
int pot2Val = 0; // variable to store the value coming from pot 2
int led1Pin = 9; // select the pin for the LED 1
int led2Pin = 10; // select the pin for the LED 2
int led3Pin = 11; //select the pin for the LED 3
void setup() {
pinMode(led1Pin, OUTPUT); // declare the led1Pin as an OUTPUT
pinMode(led2Pin, OUTPUT); // declare the led2Pin as an OUTPUT
}
//code for "chasing" LEDs
void loop() {
pot1Val = analogRead(pot1Pin); // read the value from pot 1, between 0 - 1024, for dimming
pot2Val = analogRead(pot2Pin); // read the value from pot 2, between 0 - 1024, for blinking
analogWrite(led1Pin, pot1Val/4); // dim LED to value from pot1
delay(pot2Val); // stop the program for some time, meaning, LED is on for this time
analogWrite(led1Pin, 0); // dim LED to completely dark (zero)
delay(pot2Val); // stop the program for some time, meaning, LED is OFF for this time
analogWrite(led2Pin, pot1Val/4); // dim LED to value from pot1
delay(pot2Val); // stop the program for some time, meaning, LED is on for this time
analogWrite(led2Pin, 0); // dim LED to completely dark (zero)
delay(pot2Val); // stop the program for some time, meaning, LED is OFF for this time
analogWrite(led3Pin, pot1Val/4); // dim LED to value from pot1
delay(pot2Val); // stop the program for some time, meaning, LED is on for this time
analogWrite(led3Pin, 0); // dim LED to completely dark (zero)
delay(pot2Val); // stop the program for some time, meaning, LED is OFF for this time
}
IMAGE
(Sorry the circuit looks like a rat's nest).
- Login to post comments