Lab/HW 3 – Potentiometer to control LEDs

Description
For the Lab, I used two potentiometers to control the brightness and blinking rate of the three LEDs.

Extra Point
For this portion of the Lab, I used the rotation of one potentiometer to control the brightness of the three LED’s. The other potentiometer controls the gaps and duration between the blinking of the individual LEDs.

Lab Material

 

  • Jumper cables
  • Potentiometers (2)
  • Ping pong ball diffuser
  • Cotton
  • Arduino
  • 3 LED’s
  • Breadboard

 

HW/LAB

int sensorPin_blink = A0;
int sensorPin_bright = A1;// select the input pin for the potentiometer
int ledPin = 13;
int redledPin = 9;
int blueledPin = 10;
int greenledPin = 11;// select the pin for the LED
int sensorValue_blink = 0;
int sensorValue_bright = 0;// variable to store the value coming from the sensor

void setup() {
 // declare the ledPin as an OUTPUT:
 pinMode(ledPin, OUTPUT);
 pinMode(redledPin, OUTPUT); // sets the pins as output
 pinMode(greenledPin, OUTPUT);
 pinMode(blueledPin, OUTPUT);
}

void loop() {
 // read the value from the sensor:
 sensorValue_blink = analogRead(sensorPin_blink);
 sensorValue_bright = analogRead(sensorPin_bright);
 // turn the ledPin on
 analogWrite(redledPin, sensorValue_bright/4);
 analogWrite(greenledPin, sensorValue_bright/4);
 analogWrite(blueledPin, sensorValue_bright/4);
 // stop the program for <sensorValue> milliseconds:
 delay(sensorValue_blink);
 // turn the ledPin off:
 analogWrite(redledPin, 0);
 analogWrite(greenledPin, 0);
 analogWrite(blueledPin, 0);
 // stop the program for for <sensorValue> milliseconds:
 delay(sensorValue_blink);
}

 

Extra Point

int sensorPin_blink = A0;
int sensorPin_bright = A1;// select the input pin for the potentiometer
int ledPin = 13;
int redledPin = 9;
int blueledPin = 10;
int greenledPin = 11;// select the pin for the LED
int sensorValue_blink = 0;
int sensorValue_bright = 0;// variable to store the value coming from the sensor

void setup() {
 // declare the ledPin as an OUTPUT:
 pinMode(ledPin, OUTPUT);
 pinMode(redledPin, OUTPUT); // sets the pins as output
 pinMode(greenledPin, OUTPUT);
 pinMode(blueledPin, OUTPUT);
}

void loop() {
 // read the value from the sensors:
 sensorValue_blink = analogRead(sensorPin_blink);
 sensorValue_bright = analogRead(sensorPin_bright);
 // turn the ledPin on
 analogWrite(redledPin, sensorValue_bright/4);
 delay(sensorValue_blink);
 analogWrite(blueledPin, sensorValue_bright/4);
 // stop the program for <sensorValue> milliseconds:
 delay(sensorValue_blink);
 analogWrite(greenledPin, sensorValue_bright/4);
 delay(sensorValue_blink);
 // turn the ledPin off:
 analogWrite(redledPin, 0);
 analogWrite(greenledPin, 0);
 analogWrite(blueledPin, 0);
 // stop the program for for <sensorValue> milliseconds:
 delay(sensorValue_blink);
}

IMG_7345
Video

 

Leave a Reply