Description:
I didn't get to hooking up 2 potentiometers, and the one I did hook up didn't behave exactly as expected, but I got the LED to take readings from the pots and then blink in a kind of unusual cool way. The values I got from the potentiometer were 38, 39, and 40, so what I did was take the difference of the value from 40 (0, 1, or 2), and mutliply it by so the LED got values of 0, 127, or 254 - it would go off, blink mid-bright, then all the way up, but not completely in a set pattern.
Components:
1 potentiometer, with 3 wires soldered on
2 additional wires
1 resistor
1 LED
Picture:
Arduino Code:
// This program wires a potentiometer to a LED
// The pot lets you control the brightness of the corresponding LED
// The pot values seem to go 38, 39, 40 - sometimes out of order or repeating
// So the light flashes bright, mid-level, or off, but not in a totally regular pattern
// adapted from http://www.andrew.cmu.edu/user/atriulzi/lamp/lamp.txt
// by Katherine Ahern
int value1 = 0; //Pot value of Blue LED
int value2 = 127; //doin' some funky stuff to get more variance in the LED
int value3 = 0;
int oneTwoThree = 0;
int ledpin1 = 9; //Blue LED
int pot1 = 1; //Designates Potentiometer for this LED
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.print("pot: "); //used to test
Serial.println(value1); //the value of the
delay(500); //potentiometer
Serial.println(oneTwoThree); //the value of the difference between 40 and the output of the pot
value1 = analogRead(pot1);
oneTwoThree = 40 - value1;
analogWrite(ledpin1, oneTwoThree * value2 ); //this sends brightness between 0 and 254
delay(30); //potentiometer put out values from
//0 to 1000, but the Arduino determines
//how much power to send to the LED on a
//scale from 0 to 255. (1000/255 = ~4)
}
Comments
I wonder if it's obvious...
That I am SO NEW to physical computing that I didn't realize you twist the stem of the potentiometer to get the full range of values.
o.m.g. hahaha :)
o.m.g. hahaha :)