DESCRIPTION:
We continued working with the three LED circuit we built for the previous lab. Analog inputs from potentiometers (pots) were used to change the blink speed and brightness rather than serial input (real-time). Pots are variable resistance depending on the rotation of the element. Analog inputs from the pots were read on the Arduino Uno and digitized (with 1024 resolution) which controlled the brightness and blink rate (we were given the code sketches).
Another aspect to the lab was learning to solder. We had to solder 3 wires to the pot: (1) Balck – Ground (2) Yellow – Analog (3) Red – 5V. The pot is a variable resistor that adjusted the voltage input from 0V-5V. Once the wires were soldered they were connected to their corresponding ports. I used Analog ports A2 for the provided sketches. Blink rate and brightness could be manually adjusted with the pot.
HW (see code below) – I utilized two pots for LED control – one to control brightness and the other to scroll through the LEDs). Analog ports A0 and A2 were used for the pots. A0 pot controlled brightness and A2 controlled position. As the pot was rotated, the LED’s would adjust brightness to make it appear as if a cursor was moving back and forth across the LEDs. To make this more or less apparent, the other pot adjusts brightness of the LEDs.
COMPONENTS:
1- Arduino Uno
1- Breadboard
1 – USB Cable
3- 220 ohmResistors
3- LEDs (Red, Green, Blue)
1- Soldering Iron w/ solder
1- Wire Stripper
Wire (Red, Black, Yellow)
2- Potentiometers
CODE:
/*
* one pot adjus brightness of the lEDs
* the other pot acts as a cursor
* modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
* http://www.arduino.cc/en/Tutorial/AnalogInput
* Michael Hemati
*/
int potPin1 = 2; // select the input pin for the potentiometer
int potPin2 = 0;
int ledR = 9; // select the pin for the LEDi
int ledG = 10;
int ledB = 11;
int pos = 0; // variable to store the value coming from the sensor
int bright = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
pos = analogRead(potPin1); // read the value from the sensor, between 0 - 1024
bright = analogRead(potPin2); // read the value from the sensor, between 0 - 1024
pos = pos/4;
bright = bright/4;
// BLUE
if (pos >= 0 && pos < 84)
{
analogWrite(ledB,bright);
analogWrite(ledG,bright/4);
analogWrite(ledR, bright/4);
}
// GREEN
else if (pos >= 84 && pos < 170)
{
analogWrite(ledB,bright/4);
analogWrite(ledG,bright);
analogWrite(ledR, bright/4);
}
// RED
else if (pos >= 170 && pos < 255)
{
analogWrite(ledB,bright/4);
analogWrite(ledG,bright/4);
analogWrite(ledR, bright);
}
}
- Login to post comments