17
03.09
This was part of a student lecture in the computation class. We discussed PWM and applying it to multiple LED’s and tri-color LED’s. Here’s pcitures and code for the 2 circuits I built and presented in class.
![]()
View more presentations from bruzed.
Multiple LED’s with PWM
int value = 0; // variable to keep the actual value
int pins[] = {9, 10, 11}; // light connected to digital pin 9
int numPins = 3;
void setup() { // nothing for setup
}
void loop() {
int i;
for (i=0; i < numPins; i++) {
for(value = 0 ; value <= 255; value+=5) // fade in (from min to max)
{
analogWrite(pins[i], value); // sets the value (range from 0 to 255)
delay(30); // waits for 30 milli seconds to see the dimming effect
}
}
int j;
for (j=numPins-1; j >= 0; j–) {
for(value = 255; value >=0; value-=5) // fade out (from max to min)
{
analogWrite(pins[j], value);
delay(30);
}
}
}
Tri-Color LED
// light connected to digital pin 9, 10, 11
int pins[] = {9, 10, 11};
void setup() { // nothing for setup
}
void loop() { // variable to keep the actual value
int value = 0;
//variables to check if fade in for a color is complete
int fadedIn1 = 0;
int fadedIn2 = 0;
int fadedIn3 = 0;
//variables to check if fade out for a color is complete
int fadedOut1 = 0;
int fadedOut2 = 0;
int fadedOut3 = 0;
//fade in blue
if (fadedIn1 != 1){
for(value = 255; value >=0; value-=5)
{
analogWrite(pins[1], value);
delay(60);
fadedIn1 = 1;
}
}
//fade in green
if (fadedIn2 != 1){
for(value = 255; value >=0; value-=5)
{
analogWrite(pins[0], value);
delay(60);
fadedIn2 = 1;
}
}
//fade in red
if (fadedIn3 != 1){
for(value = 255; value >=0; value-=5)
{
analogWrite(pins[2], value);
delay(60);
fadedIn3 = 1;
}
}
//fade out red
if (fadedOut1 != 1){
for(value = 0; value <=255; value+=5)
{
analogWrite(pins[2], value);
delay(60);
fadedOut1 = 1;
}
}
//fade out green
if (fadedOut2 != 1){
for(value = 0; value <=255; value+=5)
{
analogWrite(pins[0], value);
delay(60);
fadedOut2 = 1;
}
}
//fade out blue
if (fadedOut3 != 1){
for(value = 0; value <=255; value+=5)
{
analogWrite(pins[1], value);
delay(60);
fadedOut3 = 1;
}
}
}
Categories
-
Recent Posts
Tags
YouTube API processing max/msp/jitter second life actionscript PyGame XML Photoshop PHP GuitarRig Google Maps API openCV imovie supercollider picchip Ableton Live Javascript svn arduino git Illustrator After Effects last.fm Wordpress waveshield Flex Builder speakjet jQuery garageband reaktor OSCemote openGL CSS API BBPress Maya OpenFrameworks terminal audacity iphone Flash osc vsti C++ HTML AIR NYTimes runes of magic Yahoo! Weather API Python Wordpress Plugin API Newswire mrmr MySQLPeople
Archives
- January 2012
- January 2011
- November 2010
- August 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- April 2008
- March 2008
- December 2007