HUE Lights

HUE is a fading RGB LED that cycles through colors in order to meet your aesthetic needs for dorm rooms, parties, and more!

BeginnerWork in progress41
HUE Lights

Things used in this project

Hardware components

EK-TM4C123GXL TM4C Tiva LaunchPad
Texas Instruments EK-TM4C123GXL TM4C Tiva LaunchPad
×1
Breadboard (generic)
Breadboard (generic)
×1
LED, RGB
LED, RGB
×1
Jumper wires (generic)
Jumper wires (generic)
×4
Tilt Switch, SPST
Tilt Switch, SPST
×1

Software apps and online services

Energia
Texas Instruments Energia

Story

Read more

Schematics

Wiring Schematic

Code

Fade RGB LED

C/C++
cycles through colors with gradient effect in between
/*
Fade RGB LED (PWM) HUE Project
Sidekick Basic Kit for TI LaunchPad

// Connect Anode pin to VCC
// Connect Red to pin 19 which should be PWM capable
// Connect Green to pin with PWM
// Connect Blue to pin with PWM
// Connect tilt switch to pin 12
 */

// #define to rename our pins from numbers to readable variables
#define RED 19 // pin 19 is always PWM capable according to LaunchPad standard
#define GREEN 17 // pin 17
#define BLUE 11 // pin 11
#define TILT 12 // TILT SWITCH at pin 12
#define delayTime 10 // delay between color changes, 10ms by default

// Global Variables
int redVal;
int greenVal;
int blueVal;
int tiltVal;

/* Setting LED pins as OUTPUT and HIGH */
void setup() {
  
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(TILT, INPUT);
digitalWrite(TILT, HIGH);

// Test Red
digitalWrite(RED, LOW);
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, HIGH);
delay(500);
// Test Green
digitalWrite(RED, HIGH);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, HIGH);
delay(500);
// Test Blue
digitalWrite(RED, HIGH);
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, LOW);
delay(500);
}

void loop() {

  tiltVal = digitalRead(TILT); // reads the state of the tilt switch
  // if tilted, the light will turn off
  // if tilted in the other direction, the LED will continue to fade
  int PWM_RESOLUTION = 255; // holds the resolution.
  
  /* Start with full red */
  int redVal = 0; // zero voltage will give us full color
  int greenVal = PWM_RESOLUTION; // max voltage will give us no color
  int blueVal = PWM_RESOLUTION; // max voltage will give us no color
  
  analogWrite( RED, redVal );
  analogWrite( GREEN, greenVal );
  analogWrite( BLUE, blueVal );

    /*Fade from red to orange */
  for( int i = 0 ; i < 85 ; i += 1 ){
  greenVal -= 1;
  redVal += 1;
  analogWrite( RED, redVal ); // set the new red value
  analogWrite( GREEN, greenVal ); // set the new green value
  delay( delayTime ); // wait for how long delay time is
  }
  
  //  Serial.println("Orange to Yellow");
  /* Fade from orange to yellow */
  for( int i = 0 ; i < 85 ; i += 1 ){
  greenVal -= 1;
  analogWrite( GREEN, greenVal ); // set the new green value
  delay( delayTime ); // wait for how long delay time is
  }
  
  //  Serial.println("Yellow to green");
  /* Fade from yellow to green*/
  for( int i = 0 ; i < 85 ; i += 1 ){
  greenVal -= 1;
  redVal += 2;
  analogWrite( GREEN, greenVal ); // set the new green value
  analogWrite( RED, redVal);
  delay( delayTime ); // wait for how long delay time is
  }
  
  //  Serial.println("Green to aqua");
  /* Fade from green to aqua*/
  for( int i = 0 ; i < 85 ; i += 1 ){
  greenVal += 1;
  blueVal -= 1;
  analogWrite( GREEN, greenVal ); // set the new green value
  analogWrite( BLUE, blueVal);
  delay( delayTime ); // wait for how long delay time is
  }
  
  //  Serial.println("Green to aqua"); 
  /* Fade from aqua to blue*/
  for( int i = 0 ; i < 85 ; i += 1 ){
  greenVal += 2;
  blueVal -= 2;
  analogWrite( GREEN, greenVal ); // set the new green value
  analogWrite( BLUE, blueVal);
  delay( delayTime ); // wait for how long delay time is
  }
  
  //  Serial.println("Blue to purple");
  /* Fade from blue to purple*/
  for( int i = 0 ; i < 85 ; i += 1 ){
  redVal -= 1;
  blueVal += 1;
  analogWrite( RED, redVal ); // set the new green value
  analogWrite( BLUE, blueVal);
  delay( delayTime ); // wait for how long delay time is
  }
  
  //  Serial.println("Purple to pink");
  /* Fade from purple to pink*/
  for( int i = 0 ; i < 85 ; i += 1 ){
  blueVal += 1;
  redVal -= 1;
  analogWrite( BLUE, blueVal ); // set the new green value
  analogWrite( RED, redVal);
  delay( delayTime ); // wait for how long delay time is
  }
  
  //  Serial.println("Pink to red");
  /* Fade from pink to red*/
  for( int i = 0 ; i < 85 ; i += 1 ){
  blueVal += 1;
  redVal -= 1;
  analogWrite( BLUE, blueVal ); // set the new green value
  analogWrite( RED, redVal);
  delay( delayTime ); // wait for how long delay time is
  }

}

Credits

Pooja Vettical

Pooja Vettical

1 project • 0 followers
Shreyah Mohanselvan

Shreyah Mohanselvan

0 projects • 0 followers
Diep Ngoc Vu Hoang

Diep Ngoc Vu Hoang

0 projects • 0 followers
Xueyan Mu

Xueyan Mu

0 projects • 0 followers
Hung Nguyen

Hung Nguyen

0 projects • 0 followers
Douglas Graham

Douglas Graham

0 projects • 0 followers
Jenny Bechtold

Jenny Bechtold

0 projects • 0 followers
Sanjanaa Shanmugam

Sanjanaa Shanmugam

0 projects • 0 followers

Comments

Add projectSign up / Login