Looks like you're using Internet Explorer 7.0. For a better browsing experience either upgrade your browser or get a better one like Chrome.

bruzed

  • About
  • Portfolio
  • Archives
  • Contact
17
03.09

Using PWM with multiple LED’s

0
Posted in Code, Physical Computing Tagged arduino

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.

Student Lecture 3

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;
		}
	}
}



Share|

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *


+ three = 7

  • Categories

    • Code
    • Experiments
    • Interesting People/Work
    • Medium
      • Installation
      • Light
      • Physical
      • Platform
      • Print
      • Projection
      • Sound
      • Video
      • Web
    • Podcasts
    • Portfolio
    • Portfolio Archive
    • Press & Recognition
    • Prototypes
    • Thesis
    • Tools
    • Type
      • 3D
      • A/V Systems and Machines
      • Application
      • Audio Synthesis
      • Computer Vision
      • Data Visualization
      • Game Design
      • Information Design
      • Interactive Design
      • Interface Design
      • Musical Instrument
      • Performance
      • Physical Computing
      • Sound Design
      • Visual Design
      • Web Development
      • Wordpress Plugin
      • Wordpress Theme
  • Recent Posts

    • Transmutation
    • Field Internships in Information Design
    • TweetCatcha on The Huffington Post
    • Shredboard semifinalist in 2010 Adobe Design Achievement Awards
    • social sqncr @ ART|SCI, CNSI, UCLA
    • social sqncr
    • social sqncr @ MIT
    • Hypnagogia
    • social sqncr on typeslashcode blog
    • social sqncr @ onezero 2010
  • Tags

    Wordpress Plugin API last.fm git C++ Newswire PHP mrmr garageband After Effects jQuery Google Maps API terminal Illustrator NYTimes XML picchip GuitarRig Python Photoshop OpenFrameworks processing Maya osc runes of magic Flash speakjet OSCemote MySQL Yahoo! Weather API CSS BBPress PyGame Wordpress Flex Builder YouTube API Ableton Live API imovie waveshield supercollider openGL HTML openCV svn audacity Javascript iphone actionscript vsti max/msp/jitter AIR arduino second life reaktor
  • People

    • Adrienne Michetti
    • Allyscope
    • Baxter Crabtree
    • Claytical
    • David Calvo
    • Denise Flasz
    • GreyC
    • Hilary Fenton
    • Jen Cotton
    • Joe Saavedra
    • Kunal D. Patel
    • Lawrence Mascia
    • Nick Hardeman
    • Rupa DasGupta
    • sava
    • umi
    • Vargatron
  • 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

Recent Stuff

  • Transmutation
  • Field Internships in Information Design
  • TweetCatcha on The Huffington Post
  • Shredboard semifinalist in 2010 Adobe Design Achievement Awards
  • social sqncr @ ART|SCI, CNSI, UCLA

Tags

PHP BBPress Flash PyGame picchip C++ Wordpress Plugin API arduino Illustrator jQuery git CSS API Photoshop second life osc supercollider garageband Google Maps API HTML XML OSCemote audacity reaktor OpenFrameworks speakjet openGL MySQL max/msp/jitter svn Maya actionscript Python Wordpress Flex Builder openCV processing terminal Javascript AIR

Feed

  • Listened to Deceleration - Techno Animal.
  • Listened to Food For Thought - Schizoid.
  • Listened to You're a Hero - Patric Catani.

Connect

connect Twitterconnect LinkedInconnect Deliciousconnect Vimeoconnect Last.fmconnect Soundcloud

Design & code by bruzed. Powered by Wordpress