Description: The lab assignment was to use three potentiometers to control three leds in different manner. I initially had the idea of making a game of the three LEDs to teach how RGB values can be mixed and merged to form new colors. Although I was able to implement the action part of the game i.e. deciding mixing colors using the pots, I was not able to implement the interactive part of the game. I had envisioned the game to automatically suggest new colors and the users would have to match the color using the pot, the micro-controller would capture the POT values convert them in the 0-255 range and then compare with its own interpretation of the color, but the limited fidelity of the LEDs and the fluctuations in the POT analog readings made the game completely non-intuitive. Hence, I went with plan B, which is a basic LED control setup, the first POT controls intensity of all the three LEDs, the second POT controls the frequency of all the LEDs and the third POT controls the Phase difference between the three LEDs.
Components used:
1 - breadboard
2 - potentiometers
3 - LEDs
1 - Arduino
3 - 220-ohm resistors Code used:
/*
* I262 - Assignment 3
* Date: 10/1/2013
* Author: Suhaib Syed
* Input: 3 Potentionmeters
* Output: 3 LEDs
* Function: Each LED controls different aspects of the LED
* POT1 controls the brightness of the LEDs
* POT2 controls the total frequency of the LEDs
* POT3 controls the time intervals/phase difference between each LED
*/
int potPin1 = 2; // select the input pins for the potentiometers
int potPin2 = 3;
int potPin3 = 4;
int greenled = 9; // select the output pins for the LEDs
int redled = 6;
int blueled = 11;
int val1 = 0; // Variables to store the potentiometer values
int val2 = 0;
void setup() {
Serial.begin(9600); // Setting up serial connection
}
void loop() {
val1 = analogRead(potPin2)/10; // Read the values from the POT2 and 3
val2 = analogRead(potPin3)/5; // Dividing to create distince effects by using higher frequency
frequency(val1, val2); // Call function
void setled (int potPin, int led){
int val = 0; // variable to store the value coming from the sensor
val = analogRead(potPin); // read the value from the sensor, between 0 - 1024
analogWrite(led, val/4); // analogWrite can be between 0-255
}
void frequency(int val1, int val2){
setled(potPin1, greenled);
delay(val2);
setled(potPin1, blueled);
delay(val2);
setled(potPin1, redled);
delay(val2);
delay(val1); // time interval between On and Off
digitalWrite(greenled, LOW);
delay(val2);
digitalWrite(blueled, LOW);
delay(val2);
digitalWrite(redled, LOW);
delay(val2);
delay(val1);
}
- Login to post comments