Description:
This Lab and homework is designed to teach how to use soldering to create physical electrical connections to new types of physical input devices with wires. The lab focused on using potentiometers as a source of analog input to use with the set of blinking LEDs to measure the output effects.
I did not have time to create a third potentiometer, so for this assignment I am using the combination of two potentiometers to capture analog inputs on the same set of LEDs (Red, Blue and Green)
I am using the potentiometers to adjust the blinking of the LEDs in two different ways:
1) Pot1_BlinkSequence will adjust the blinking delay for the successive sequence of turning on the LEDs in the order red, green and blue. For instance, if there is “no delay”, in essence all three LEDS will be turned on at once. Example: Pot1_BlinkSequence = 0 > Red,Green,Blue lights are all turned on at once. Pot1_BlinkSequence = 1024, LEDS will blink in sequence Red, Green, Blue.
2) Pot2_IntervalSequence will be used to adjust the successive blinking sequence of the set of LEDs at once. Pot2_IntervalSequence = 0, there is no delay between the start of the LEDBlinkSequence.
The program allows the potentiometers to vary the interval of LED blinking as a set and within the set of LEDs adjust whether the LEDS blink in unison.
Example Combinations:
1) All LEDs are Turned on: Pot1_BlinkSequence = 0 ; Pot2_IntervalSequence = 0;
2) ALL LEDs are Turned on and Blink in unison in 1 second Intervals: Pot1_BlinkSequence = 0 ; Pot2_IntervalSequence = 1024;
3) LEDs blink on in sequence at 1 second delays waits 1 second and starts again: Pot1_BlinkSequence = 1024 ; Pot2_IntervalSequence = 1024;
4) LEDs blink on in sequence in 1 second intervals: Pot1_BlinkSequence = 1024 ; Pot2_IntervalSequence = 0;
Components Used:
1- Breadboard
1- Arduino Uno
3 LEDs (Red, Blue, Green)
1 USB interface cable to Arduino
3 220 Ohm Resistors
2 Potentiometers
Code:
/*
* This program uses the two sets of potentiometers to capture analog input to manipulate the sequence of three LEDs lights.
*
*
*/
int pot1Pin = 0; // select the input pin for the potentiometer 1
int pot2Pin = 1; // select the input pin for the potentiometer 2
int pot1Val = 0; // variable to store the value coming from pot 1
int pot2Val = 0; // variable to store the value coming from pot 2
int ledRedPin = 9; // select the pin for the LED 1
int ledGreenPin = 10;
int ledBluePin = 11; // select the pin for the LED 2
int val = 0;
void setup() {
pinMode(ledRedPin, OUTPUT); // declare the led1Pin as an OUTPUT
pinMode(ledGreenPin, OUTPUT); // declare the led2Pin as an OUTPUT
pinMode(ledBluePin, OUTPUT); // declare the led2Pin as an OUTPUT
Serial.begin(9600);
}
void loop() {
pot1Val = analogRead(pot1Pin); // read the value from pot 1, between 0 - 1024, for dimming
pot2Val = analogRead(pot2Pin); // read the value from pot 2, between 0 - 1024, for blinking
blinkLedSequenceOn(pot1Val, 125);
delay(pot2Val);
if(pot2Val > 5){
turnOffAllLEDs();
}
delay(pot2Val);
//Serial.println(pot1Val);
}
void blinkLedSequenceOn(int inputTime, int value){
int delayTime;
if (inputTime < 5) {
delayTime = 0;
Serial.println(inputTime);
}else {
delayTime = inputTime;
}
/* Program turns on the LEDs (Red -> Green-> Blue) and introduces a delay
*/
////Flash on LEDs
analogWrite(ledRedPin, value); // dim LED to value from pot1
delay(delayTime); // stop the program for some time, meaning, LED is on for this time
analogWrite(ledGreenPin, value); // dim LED to value from pot1
delay(delayTime); // stop the program for some time, meaning, LED is on for this time
analogWrite(ledBluePin, value); // dim LED to value from pot1
delay(delayTime); // stop the program for some time, meaning, LED is on for this time
if(delayTime !=0)
turnOffAllLEDs();
}
/* Function turns off all LEDs
*/
void turnOffAllLEDs(){
analogWrite(ledRedPin, 0); // dim LED to completely dark (zero)
analogWrite(ledGreenPin, 0);
analogWrite(ledBluePin, 0);
}
- Login to post comments