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 *


4 − two =

  • 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

    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 MySQL
  • 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

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

Feed

  • Listened to Black Hand Side - Queen Latifah.
  • Listened to Show Me Love - Robin S.
  • Listened to Regulate - Warren G.

Connect

connect Twitterconnect LinkedInconnect Deliciousconnect Vimeoconnect Last.fmconnect Soundcloud

Design & code by bruzed. Powered by Wordpress