Arduino Project
Project Description
A basic use of Arduino explored through a super cool mood lamp
Project Materials
1 arduino
1 usb cable
1 RGB LED
4 330 Ohm resistors
1 small breadboard
4 long jumper wires (different colors)
1 square? jar glass
1 white candle unscented
Acrylic paint blue
spongy brush
Wiring materials:
2 red wires
2 black wires
1 blue wire
1 green wire
1 RGB LED
1 small breadboard
1 arduino uno
// Smooth RGB mood lamp
// Changes an RGB LED's color smoothly that only turns on
ACTUAL WORKING CODE
// Ambient RGB light
// Author: Kristoffer Scott
//
// Controls RGB LEDs; smoothly transitions through color values.
// Delay time: sets the time in milliseconds between loop iterations.
// Make this value large for slower transitions.
#define DELAY_TIME 150
// Maximum Brightness: the maximum level the pins will reach.
#define MAX_BRIGHT 255
// The pins which each color value is output to.
#define PIN_RED 10
#define PIN_GREEN 9
#define PIN_BLUE 8
// The initial values of each color.
int red = 0;
int green = 170;
int blue = 170;
// Indicates whether a color is incrementing (1) or decrementing (0).
int incR = 1;
int incG = 1;
int incB = 0;
// Smoothly changes the color values
void transition()
{
if (red >= MAX_BRIGHT)
incR = 0;
else if (red <= 0)
incR = 1;
if (green >= MAX_BRIGHT)
incG = 0;
else if (green <= 0)
incG = 1;
if (blue >= MAX_BRIGHT)
incB = 0;
else if (blue <= 0)
incB = 1;
if (incR)
red++;
else
red--;
if(incG)
green++;
else
green--;
if(incB)
blue++;
else
blue--;
}
// Sets the output voltage on the LED pins.
void setColor()
{
analogWrite(PIN_RED, red);
analogWrite(PIN_GREEN, green);
analogWrite(PIN_BLUE, blue);
}
void setup()
{ // Do nothing.}
void loop()
{ transition();
setColor();
delay(DELAY_TIME);
}
1 usb cable
1 RGB LED
4 330 Ohm resistors
1 small breadboard
4 long jumper wires (different colors)
1 square? jar glass
1 white candle unscented
Acrylic paint blue
spongy brush
Wiring materials:
2 red wires
2 black wires
1 blue wire
1 green wire
1 RGB LED
1 small breadboard
1 arduino uno
// Smooth RGB mood lamp
// Changes an RGB LED's color smoothly that only turns on
ACTUAL WORKING CODE
// Ambient RGB light
// Author: Kristoffer Scott
//
// Controls RGB LEDs; smoothly transitions through color values.
// Delay time: sets the time in milliseconds between loop iterations.
// Make this value large for slower transitions.
#define DELAY_TIME 150
// Maximum Brightness: the maximum level the pins will reach.
#define MAX_BRIGHT 255
// The pins which each color value is output to.
#define PIN_RED 10
#define PIN_GREEN 9
#define PIN_BLUE 8
// The initial values of each color.
int red = 0;
int green = 170;
int blue = 170;
// Indicates whether a color is incrementing (1) or decrementing (0).
int incR = 1;
int incG = 1;
int incB = 0;
// Smoothly changes the color values
void transition()
{
if (red >= MAX_BRIGHT)
incR = 0;
else if (red <= 0)
incR = 1;
if (green >= MAX_BRIGHT)
incG = 0;
else if (green <= 0)
incG = 1;
if (blue >= MAX_BRIGHT)
incB = 0;
else if (blue <= 0)
incB = 1;
if (incR)
red++;
else
red--;
if(incG)
green++;
else
green--;
if(incB)
blue++;
else
blue--;
}
// Sets the output voltage on the LED pins.
void setColor()
{
analogWrite(PIN_RED, red);
analogWrite(PIN_GREEN, green);
analogWrite(PIN_BLUE, blue);
}
void setup()
{ // Do nothing.}
void loop()
{ transition();
setColor();
delay(DELAY_TIME);
}