Components
• 1 Arduino Uno
• 3 resistor (220 ohms)
• 3 pots
• 3 LEDs (red, blue, green)
• 1 breadboard
• 1 USB cable
• Jumper wires
• Laptop
Description
For this lab I used my Arduino Uno board to control the brightness of the three LEDs, by manipulating 3 pots.
Code
int sensorRed = A0; // select the input pin for the potentiometer 1
int sensorBlue = A1; // select the input pin for the potentiometer 2
int sensorGreen = A2; // select the input pin for the potentiometer 3
int redPin = 9; // select the pin for the red LED
int bluePin = 10; // select the pin for the blue LED
int greenPin = 11; // select the pin for the green LED
int redValue=0;
int blueValue=0;
int greenValue=0;
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
// read the values from the sensors:
redValue = analogRead(sensorRed);
blueValue = analogRead(sensorBlue);
greenValue = analogRead(sensorGreen);
redValue=(redValue/4);
blueValue=(blueValue/4);
greenValue=(greenValue/4);
analogWrite(redPin, redValue);
analogWrite(bluePin, blueValue);
analogWrite(greenPin, greenValue);
}