Components
- 1 Arduino
- 1 breadboard
- 3 LEDs (red, green, blue)
- 3 potentiometers
- 3 225-ohm resisters
- wires
For this lab/hw, I controlled the brightness of each LED with a different potentiometer.
Code
// initialize pot pins
int potPin1 = A0;
int potPin2 = A2;
int potPin3 = A3;
// set pot values;
int potV1 = 0;
int potV2 = 0;
int potV3 = 0;
// initialize leds
int blueLed = 6;
int redLed = 9;
int greenLed = 11;
void setup() {
Serial.begin(9600);
// declare the led pin as an output:
pinMode(blueLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
}
void loop() {
potV1 = analogRead(potPin1);
potV2 = analogRead(potPin1);
potV3 = analogRead(potPin1); // read the pot value
analogWrite(blueLed, potV1/4);
analogWrite(redLed, potV2/4);
analogWrite(greenLed, potV3/4);
delay(10); // wait a bit, for serial data
}