Making Furniture Interactive

September 4, 2007

zero: pulsating ball

Filed under: Exercise 0: Make A Lamp — bosmet @ 9:27 pm
  • Configuration:
  • To make a multi-colored light, you need to use three leds of different color that alternate in time and brightness. I connected a red, green and blue led to the digital pwm-ports 9, 10 & 11 respectively. You need to put resistors in series to protect them from burning through and connect the short sides of the leds to the ground (GND) port next the digital ports on the board. I wanted to let the leds fade in different intervals so that the overall color of the lamp would change all the time. By putting them in an opaque enclosure – for example a ping pong ball, the leds blend into one color.

    

    Configuration for lamp

  • Programming:
  • To program the arduino to fade you first have to declare the output ports: digital pwm-outputs 9, 10 & 11. Then by a series of for-commands, you can let the leds fade in and out. By setting the value steps and the delay you can control the speed and brightness of the leds to form patterns. The red and green leds alternate by fading in and out at the same interval but with opposite values. You can achieve this by changing the value in the analogWrite command for the green led into 255 – value. When the sequence starts, the value for the red led equals 0, so the value for the green led equals 255 – 0 = 255. The fading out command has an opposite result, so the red led will go from 255 to 0 and the green led from 0 to 255. When the green led is at its brightest value and the red led is out, the blue one fades in and out, then the cycle restarts. To make the blue led less bright, you have to fix the maximum value at something less than 255, like 70 or so.

  • Actual Code:

  • int value = 0;
    int red = 9; //Declaring the ports to which the leds are connected.
    int green = 10;
    int blue = 11;

    void setup()
    {
    //nothing needed in the setup
    }

    void loop()
    {
    for(value = 0 ; value =0; value-=5) //For fading out, the value goes down in steps of 5.
    {
    analogWrite(red, value);
    analogWrite(green, 255 - value); //Now the green led starts at 0 and goes up to 255.
    delay(50);
    }
    for(value = 0 ; value =0; value-=2)
    {
    analogWrite(blue, value);
    delay(50);
    }
    }

    Advertisements

    Leave a Comment »

    No comments yet.

    RSS feed for comments on this post. TrackBack URI

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s

    Blog at WordPress.com.