Announcements

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!


Boring Blinky Dimmy LEDs

Project Members: 
Matt Chew Spence

Description

Used potentiometers as analog input to control brightness and sequential blinking rate of RBG LEDs.  Modified provided arduino code with lab so that the three LEDs in blink individually in sequence, with one potentiometer controlling the rate at which the LEDs switch from one to another, and the other potentiometer controlling the brightness of all three LEDs

Components

  • 1ea Red LED, Green LED, Blue LED
  • 3ea 220 Ohm Resistors
  • 1ea Diffuser made from Post-it and plastic grocery bag
  • 2ea Potentiometers

Arduino Code

/*
* Boring little led program
*
* Red, Green, and Blue LEDs blink in sequence

* one pot (pot1) dims, the other pot changes the blinking rate
* modification of the following
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/

//set analog input pins for potentiometers
int pot1Pin = 2; // select the input pin for the potentiometer 1
int pot2Pin = 3; // select the input pin for the potentiometer 2

//create variables to store incoming potentiometer data
int pot1Val = 0; // variable to store the value coming from pot 1
int pot2Val = 0; // variable to store the value coming from pot 2

//set analog out pins for LEDs
int led1Pin = 9; // select the pin for the LED 1 (Red)
int led2Pin = 10; // select the pin for the LED 2 (Green)
int led3Pin = 11; // select the pin for the LED 3 (Blue)

//intialize variables for LED sequence calculation
int counter;
int calcLed;
int off1Led;
int off2Led;

void setup() {
pinMode(led1Pin, OUTPUT); // declare the led1Pin as an OUTPUT
pinMode(led2Pin, OUTPUT); // declare the led2Pin as an OUTPUT
pinMode(led3Pin, OUTPUT); // declare the led3Pin as an OUTPUT
}
void loop() {
for(counter = 0; counter <= 255; counter++)
{
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

calcLed = (counter % 3) + 9 ; // Determine which LED to light

delay(pot2Val); // stop the program for some time, meaning, LED is on for this time

// if time for Red to light up
if (calcLed == led1Pin) {
analogWrite(led1Pin, pot1Val/4); // dim LED to value from pot1
off1Led = calcLed + 1; // calcuate other two LEDs to extinguish
off2Led = calcLed + 2;
} else {
// else if time for Green to light up
if (calcLed == led2Pin) {
analogWrite(led2Pin, pot1Val/4); // dim LED to value from pot1
off1Led = calcLed + 1; // calcuate other two LEDs to extinguish
off2Led = calcLed - 1;
} else {
// else it is time for blue to light up
analogWrite(led3Pin, pot1Val/4); // dim LED to value from pot1
off1Led = calcLed - 1; // calcuate other two LEDs to extinguish
off2Led = calcLed - 2;
}
}
analogWrite(off1Led, 0); // dim off1Led to completely dark (zero)
analogWrite(off2Led, 0); // dim off2Led to completely dark (zero)
delay(pot2Val); // stop the program for some time, meaning, LED is OFF for this time
}
}
TUI lab 3TUI lab 3


Comments

nice job! good novel

nice job! good novel assignment of your pot to the rate of LED changes.


Powered by Drupal - Design by Artinet