November 24, 2007
Reading for November 27th, are now posted. Enjoy!

October 2, 2007
To upload your thoughtless acts, create a new assignment page like any other lab. You'll see "Thoughtless Acts" listed as one of the assignment options.

May 24, 2008
This site has been archived and is no longer editable. Stay tuned for the next version, coming in the fall!

Lab 3

Project Members: 
Igor P

Analog Input and LEDs


The grad finale is a two pot controlled circuit. One pot controls which of the three LEDs is listening to the second pot. The second pot controlls the brightness of the LED currently listening.

When POT1 is all the way to the left, POT2 controls blue LED. When POT1 is midway, POT2 controls the red LED. When POT1 is all the way to the right, POT2 is controlling the green LED.

One catch is wanting to set the blue and then set the green LED. Because POT1 fist has to go through the red LED, you also have to set that one. So in this case a pot is not a good three-way switch. But it works.

Another catch was about 30 min of wasted time until I noticed that only pins marked "PWM" (something wave modulation) will work for the fading LED circuit. Good thing to know.




Components used

red, blue, green LEDs

2 pots

3 resistors (red/red/brown/gold)

Arduino Code

// Pot 1 - Brightness
int potPinBright = 0; // select the input pin for the potentiometer
int potValBright = 0; // variable to store the value coming from the sensor

// Pot 2 - Switch between led's
int potPin2 = 3;
int potVal2 = 0;

// Output
int redPin = 5; // Red LED, connected to digital pin 9
int greenPin = 3; // Green LED, connected to digital pin 10
int bluePin = 6; // Blue LED, connected to digital pin 11

// Program variables
int redVal = 255; // Variables to store the values to send to the pins
int greenVal = 255; // Initial values are Red full, Green and Blue off
int blueVal = 255;

int i = 0; // Loop counter
int wait = 10; // 50ms (.05 second) delay; shorten for faster fades
int DEBUG = 1; // DEBUG counter; if set to 1, will write values back via serial

void setup()
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);

Serial.begin(9600); // ...set up the serial ouput on 0004 style

// Main program
void loop()
potVal2 = analogRead(potPin2); // read the value from the sensor, between 0 - 1024
potValBright = analogRead(potPinBright); // read the value from the sensor, between 0 - 1024

if (potVal2 < 341) // First third of pot range
redVal = potValBright/4; // Set the red led
else if (potVal2 >= 341 && potVal2 < 682) // Second third of pot range
greenVal = potValBright/4; // Set the green led
else if (potVal2 >= 682) // Third third of pot rnage
blueVal = potValBright/4; // Set the blue led

analogWrite(redPin, redVal); // Write current values to LED pins
analogWrite(greenPin, greenVal);
analogWrite(bluePin, blueVal);

delay(wait); // Pause for 'wait' milliseconds before resuming the loop


thanks for getting this up.

thanks for getting this up.

Powered by Drupal - Design by Artinet