Description
I created a system with 3 potentiometers and 3 LEDs in which each potentiometer controls one LED.
Materials used
Red LED
Blue LED
Green LED
3 potentiometers
Code
/*
* 3 potentiometers control 3 LEDs
* modified version of AnalogInput
* by Chelsey Tanaka
*/
int pot1 = 1; // select the input pin for potentiometer 1
int pot2 = 2; // select input pin for potentiometer 2
int pot3 = 3; // select input pin for potentiometer 3
int led1 = 9; // select the pin for LED 1
int led2 = 10; // select the pin for LED 2
int led3 = 11; // select the pin for LED 3
int potVal1 = 0; // variable to store the value coming from potentiometer 1
int potVal2 = 0; // variable to store value from potentiometer 2
int potVal3 = 0; // variable to store value from potentiometer 3
void setup() {
Serial.begin(9600);
}
void loop() {
potVal1 = analogRead(pot1); // read value from pot1, between 0 - 1024
Serial.println(potVal1);
analogWrite(led1, potVal1/4); // analogWrite can be between 0-255
potVal2 = analogRead(pot2); // read value from pot1, between 0 - 1024
Serial.println(potVal2);
analogWrite(led2, potVal2/4); // analogWrite can be between 0-255
potVal3 = analogRead(pot3); // read value from pot1, between 0 - 1024
Serial.println(potVal3);
analogWrite(led3, potVal3/4); // analogWrite can be between 0-255
}