Description:
In this lab we used a sodering iron and soder to connect wires to devices called potentiometers and we used them as analog reads. One wire hooked up to the power source, the other to the analog input, and the final wire to the ground. We then hooked these 'pots' up to the pre-existing circuit we had built from last week and tested generic code to test that the pots worked. Our homework assignment was to use one pot to control the blinking of the LEDs and the other pot to control the brightness of the LEDs. Not coming from a programming background myself, I analyzed the provided code and consolidated it into a single 'sketch' that was verified by the Arduino program as being complete. It required setting all variables in the same script and including both the analogwrite and the digitalwrite in the same void loop.
Components:
1- Arduino Uno
3- LEDs
2- Potentiometers
14- wires
3- 220 ohm resistors
1- sodering iron + soder
Code:
// This code controls the 3 LED lights in two different ways. The first is through manipulating
// the blink speed of the LED through one potentiometer and the brightness through another.
// -Justin Sampson
int potBlink = 0; // input pin for the potentiometer controlling blinking
int potDim = 1; // input pin for the potentiometer controlling brightness
int ledPinBlue = 9; // select the pin for the blue LED
int ledPinGreen = 10; // select the pin for the green LED
int ledPinRed = 11; // select the pin for the red LED
int blinkvalue = 0; // variable storing blink-sensor value
int dimvalue = 0; // variable storing brightness-sensor value
void setup() {
pinMode(ledPinBlue, OUTPUT); // ledPin as an OUTPUT
pinMode(ledPinGreen, OUTPUT); // ledPin as an OUTPUT
pinMode(ledPinRed, OUTPUT); // ledPin as an OUTPUT
Serial.begin(9600);
}
void loop() {
blinkvalue = analogRead(potBlink); // read the value from the blink-sensor
dimvalue = analogRead(potDim); // read the value from the bright sensor
digitalWrite(ledPinBlue, LOW); // turn the blue ledPin off
digitalWrite(ledPinGreen, LOW); // turn the green ledPin off
digitalWrite(ledPinRed, LOW); // turn the red ledPin off
delay(blinkvalue); // stop the program for some time
analogWrite(ledPinBlue, dimvalue/4); // analogWrite can be between 0-255
analogWrite(ledPinGreen, dimvalue/4);
analogWrite(ledPinRed, dimvalue/4);
delay(blinkvalue); // stop the program for some time
}
- Login to post comments