Description
This third lab focused on external manipulation of LEDs.
My hardware consisted of 3 LEDs (colors: red, green and blue) and 2 potentiometers. The code was set up so that when one of the potentiometers was swiveled, the brightness of the LEDs would be affected, and when the other potentiometer was swiveled the frequency of the LEDs blinking would be altered.
Components Used
1 - Arduino Uno
1 - Mini Breadboard
1 - Red LED
1 - Green LED
1 - Blue LED
2 - Potentiometers
3 - 220 Ω Resistors
Code
/*
Bigazzi Lab 3
Multiple Pots
*/
int potPinColor = 0; // select the input pin for the potentiometer
int valColor = 0; // variable to store the value coming from the sensor
int potPinBlink= 1;
int valBlink = 0;
int ledPinB = 11;
int ledPinR = 10;
int ledPinG = 9;
void setup() {
Serial.begin(9600);
}
void loop() {
valColor = analogRead(potPinColor); // read the value from the sensor, between 0 - 1024
valBlink = analogRead(potPinBlink);
analogWrite(ledPinG, valColor/4); // analogWrite can be between 0-255
analogWrite(ledPinR, valColor/4);
analogWrite(ledPinB, valColor/4);
delay(valBlink);
digitalWrite(ledPinG, LOW);
digitalWrite(ledPinR, LOW);
digitalWrite(ledPinB, LOW);
delay(valBlink);
}
- Login to post comments