Assignment: Sensing: Potentiometers
Collaborators: jonyen
Description
Made a circuit that would allow potentiometers to control the LEDs. For my project, I programmed the board so that pot 1 controls the brightness, pot 2 controls the blinking rate, and pot 3 controls which LEDs are on/blinking.
Components
3 potentiometers
3 LEDs
Code
/* Lab 3
Pot 1 controls brightness
Pot 2 controls blinking rate
Pot 3 controls which LED(s) are on/blinking
*/
// Analog pin settings
int aIn = 0; // Potentiometers connected to analog pins 0, 1, and 2
int bIn = 1; // (Connect power to 5V and ground to analog ground)
int cIn = 2;
// Digital pin settings
int aOut = 9; // LEDs connected to digital pins 9, 10 and 11
int bOut = 10; // (Connect cathodes to digital ground)
int cOut = 11;
// Values
int aVal = 0; // Variables to store the input from the potentiometers
int bVal = 0;
int cVal = 0;
void setup()
{
pinMode(aOut, OUTPUT); // sets the digital pins as output
pinMode(bOut, OUTPUT);
pinMode(cOut, OUTPUT);
}
void loop()
{
aVal = analogRead(aIn) / 4; // read input pins, convert to 0-255 scale
bVal = analogRead(bIn);
cVal = analogRead(cIn) / 4;
digitalWrite(aOut, LOW);
digitalWrite(bOut, LOW);
digitalWrite(cOut, LOW);
delay(bVal);
if (cVal < 51) {
analogWrite(aOut, aVal); // Send new values to LEDs
analogWrite(bOut, aVal);
analogWrite(cOut, aVal);
} else if (cVal >= 51 && cVal < 102) {
analogWrite(aOut, aVal); // Send new values to LEDs
} else if (cVal >= 102 && cVal < 153) {
analogWrite(bOut, aVal);
} else if (cVal >= 153 && cVal < 204) {
analogWrite(cOut, aVal);
}
delay(bVal);
}
