Lab 3 - Potentiometers
Description
This program turns on and off a LED. The amount of time the LED will be on and off and the brightness depends on the input of a two potentiometers.
Components used
- Breadboard
- Arduino Uno
- red, green and blue LED
- 3 220 ohm resisters
- 4 ground cables
- 3 power cables
- USB cable
- 2 potentiometers
Code
/*
*
* Turns on and off a light emitting diode(LED) connected to digital
* pin 11. The amount of time the LED will be on and off depends on
* the value obtained by the potentiometer connected to analog pin 1.
* The brightness of the LED depends of the value obtained by the
* potentiometer connected to analog pin 1.
*
*/
int potPinBlink = 1; // select the input pin for the potentiometer controlling the blinking
int potPinDim = 2; // select the input pin for the potentiometer controlling the brightness
int ledPin = 11; // select the pin for the LED
int valDim = 0; // variable to store the value coming from the brightness sensor
int valBlink = 0; // variable to store the value coming from the blinking sensor
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
}
void loop() {
valDim = analogRead(potPinDim); // read the value from the DimPot
valBlink = analogRead(potPinBlink); // read the value from the BlinkPot
analogWrite(ledPin, valDim/4); // turn the ledPin on by the value of the DimPot
delay(valBlink); // stop the program for the time set by the BlinkPot
analogWrite(ledPin, LOW); // turn the ledPin off
delay(valBlink); // stop the program for the time set by the BlinkPot
analogWrite(ledPin, valDim/4); // turn the ledPin on by the value of the DimPot
}
- Login to post comments
Drupal theme by Kiwi Themes.