Rainbow Vibe Lights

Recreate your favorite night lights from the Rainbow Building with rainbow vibe lights.

BeginnerWork in progress28
Rainbow Vibe Lights

Things used in this project

Hardware components

Tilt Switch, SPST
Tilt Switch, SPST
×1
EK-TM4C123GXL TM4C Tiva LaunchPad
Texas Instruments EK-TM4C123GXL TM4C Tiva LaunchPad
×1
Grove Starter Kit for LaunchPad
Seeed Grove Starter Kit for LaunchPad
×1
Jumper wires (generic)
Jumper wires (generic)
×12
Resistor 1k ohm
Resistor 1k ohm
×2
PTS 645 Series Switch
C&K Switches PTS 645 Series Switch
×1
RGB Diffused Common Anode
RGB Diffused Common Anode
×1

Story

Read more

Schematics

Mood Light Final Schematic

Schematic for RGB LED, Tilt Switch, and Push Button setup for the mood light.

Code

Code for Mood Light System

C/C++
This code provides functionality for our fading RGB LED, allowing for the LED to fade, for the tilt switch to change frequency, and for the push button to pause the fade. More details can be seen in the code comments below.
/*
Project: Rainbow Vibe Lights
TM4C123GXL

We are going to make a fading RGB LED Vibe Light, with two key functionality:
a tilt switch that lets us change the frequncy of flashing, and a button
that lets us pause the flashing. We use Pulse Width Modulation to Facilitate the Fade

Hardware Required
TM4C123GXL Launchpad
1 Tilt Switch
1 Push Button
2 1k Ohm Resistors
12 Jumper Wires
1 Common Anode RGB LED

Hardware setup can be seen in schematic above
*/

// Rename pin numbers for easier use
#define RED 19 // Pin 19 connected to red LED
#define GREEN 17 // Pin 17 connected to green LED
#define BLUE 15 // Pin 15 connected to blue LED
#define SWITCH 13 // Pin that checks if switch is on or off
#define BUTTON 5 // Pin 5 is connected to potentiometer reading
#define delayTime0 5 // Slow delay time
#define delayTime1 1 // Fast delay time

// Global variables to store pins read from/written to pins
int redVal;
int greenVal;
int blueVal;
int buttonVal;

void setup() {
 // Set whether each pin we are using is input or ouput
 pinMode(RED, OUTPUT);
 pinMode(GREEN, OUTPUT);
 pinMode(BLUE, OUTPUT);
 pinMode(SWITCH, INPUT);
 pinMode(BUTTON, INPUT);
}

void loop() {
   int PWM_RESOLUTION = 255;

 // Read whether switch is on or off to decide rate of flashing
 if (digitalRead(SWITCH) == HIGH) {
   // Start LED as red
   redVal = 0;
   greenVal = PWM_RESOLUTION;
   blueVal = PWM_RESOLUTION;
   analogWrite( RED, redVal );
   analogWrite( GREEN, greenVal );
   analogWrite( BLUE, blueVal );
   
   // Fade the LED from red to green
   for( int i = 0 ; i < PWM_RESOLUTION ; i += 1 ){
   greenVal -= 1;
   redVal += 1;
   analogWrite( RED, redVal ); // set the new red value
   analogWrite( GREEN, greenVal ); // set the new green value

   // Check periodically if switch has been flipped
   if (digitalRead(SWITCH) == LOW){
   return;
   }

   // Pause flashing if button is held
   while (digitalRead(BUTTON) == HIGH){ 
   }


   // Wait for specified delay
   delay( delayTime0 );
   }

   // Start the LED as green
   redVal = PWM_RESOLUTION;
   greenVal = 0;
   blueVal = PWM_RESOLUTION;
   analogWrite( RED, redVal );
   analogWrite( GREEN, greenVal );
   analogWrite( BLUE, blueVal );
  
   // Fade the LED from green to blue
   for( int i = 0 ; i < PWM_RESOLUTION ; i += 1 ){
   blueVal -= 1;
   greenVal += 1;
   analogWrite( BLUE, blueVal );
   analogWrite( GREEN, greenVal );

   // Periodically check if switch has been flipped
   if (digitalRead(SWITCH) == LOW){
    return;
   }

   // Pause flashing if button is held
   while (digitalRead(BUTTON) == HIGH){
   }

   // Wait for specified delay
   delay( delayTime0 );
   }

   // Start LED as blue 
   redVal = PWM_RESOLUTION;
   greenVal = PWM_RESOLUTION;
   blueVal = 0;
   analogWrite( RED, redVal );
   analogWrite( GREEN, greenVal );
   analogWrite( BLUE, blueVal );
  
   // Fade the LED from blue to red
   for( int i = 0 ; i < PWM_RESOLUTION ; i += 1 ){
   redVal -= 1;
   blueVal += 1;
   analogWrite( RED, redVal ); // set the new red value
   analogWrite( BLUE, blueVal ); // set the new blue value

   // Check periodically if switch has been flipped
   if (digitalRead(SWITCH) == LOW){
    return;
   }

   // Pause flashing if button is held
   while (digitalRead(BUTTON) == HIGH){
   }

   // Wait for specified delay
   delay( delayTime0 );
   }

 }
 else {
   // Start the LED as red
   redVal = 0;
   greenVal = PWM_RESOLUTION;
   blueVal = PWM_RESOLUTION;
   analogWrite( RED, redVal );
   analogWrite( GREEN, greenVal );
   analogWrite( BLUE, blueVal );
  
   // Fade LED from red to green
   for( int i = 0 ; i < PWM_RESOLUTION ; i += 1 ){
   greenVal -= 1;
   redVal += 1;
   analogWrite( RED, redVal ); // set the new red value
   analogWrite( GREEN, greenVal ); // set the new green value

   // Check periodically if switch has been flipped
   if (digitalRead(SWITCH) == HIGH){
    return;
   }

   // Pause flashing if button is held
   while (digitalRead(BUTTON) == HIGH){
   }

   // Wait for specified delay
   delay( delayTime1 );
   }
  
   // Start LED green
   redVal = PWM_RESOLUTION;
   greenVal = 0;
   blueVal = PWM_RESOLUTION;
   analogWrite( RED, redVal );
   analogWrite( GREEN, greenVal );
   analogWrite( BLUE, blueVal );
  
   // Fade LED from green to blue
   for( int i = 0 ; i < PWM_RESOLUTION ; i += 1 ){
   blueVal -= 1;
   greenVal += 1;
   analogWrite( BLUE, blueVal ); // set the new blue value
   analogWrite( GREEN, greenVal ); // set the new green value

   // Check periodically if switch has been flipped
   if (digitalRead(SWITCH) == HIGH){
    return;
   }

   // Pause flashing if button is held
   while (digitalRead(BUTTON) == HIGH){
   }

   // Wait for specified delay time
   delay( delayTime1 );
   }

   // Set LED to blue
   redVal = PWM_RESOLUTION; // max voltage will give us no color
   greenVal = PWM_RESOLUTION; // max voltage will give us no color
   blueVal = 0; // zero voltage will give us full color
   analogWrite( RED, redVal );
   analogWrite( GREEN, greenVal );
   analogWrite( BLUE, blueVal );
  
   // Fade LED from blue to red
   for( int i = 0 ; i < PWM_RESOLUTION ; i += 1 ){
   redVal -= 1;
   blueVal += 1;
   analogWrite( RED, redVal ); // set the new red value
   analogWrite( BLUE, blueVal ); // set the new blue value

   // Check periodically if switch has been flipped
   if (digitalRead(SWITCH) == HIGH){
    return;
   }

   // Pause flashing if button is held
   while (digitalRead(BUTTON) == HIGH){
   }
   
   // Wait for specified delay time
   delay( delayTime1 );
   }
 }
}

Credits

Rachel Wang

Rachel Wang

1 project • 0 followers
Kelly Huang

Kelly Huang

1 project • 1 follower
Michael Tang

Michael Tang

1 project • 0 followers
Pete Sirithanachai

Pete Sirithanachai

1 project • 1 follower
Ryan Draper

Ryan Draper

1 project • 0 followers
Mark Pepperl

Mark Pepperl

1 project • 0 followers
Jae Ku

Jae Ku

1 project • 0 followers
Alex Berlaga

Alex Berlaga

0 projects • 0 followers

Comments

Add projectSign up / Login