DESCRIPTION:
The goal of this assignment was to introduce us to controlling LEDs with potentiometers. I used two potentiometers in the circuit, one that controlled brightness of the LEDs, and one that controlled blinking. I put a diffuser over it so I could see the colours fade into each other better. Because of the pots, I had control over the LEDs at an extended range.
COMPONENTS:
1- Arduino Uno
1- Breadboard
1- USB Cable
2- Potentiometers
3- 220Ω Resistors
3- LEDs, RGB
/*
* one pot dims, the other pot changes the blinking rate
* modification of the following
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int pot1Pin = 11; // select the input pin for the potentiometer 1
int pot2Pin = 12; // 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 = 8; // select the pin for the LED 2
void setup() {
pinMode(led1Pin, OUTPUT); // declare the led1Pin as an OUTPUT
pinMode(led2Pin, OUTPUT); // declare the led2Pin as an OUTPUT
}
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(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
}
- Login to post comments