Gamer Pro RGB Lighting

Enhance your gaming experience with speed-adjustable color shifting RGB gamer lights!

BeginnerFull instructions provided591
Gamer Pro RGB Lighting

Things used in this project

Story

Read more

Schematics

Schematic Diagram

Code

Gamer Pro RGB Lighting

Arduino
/*
 GAMER RGB LED
 Sidekick Basic Kit for TI LaunchPad

 Hardware Required:
 * TI LaunchPad
 * Breadboard BoosterPack
 * Breadboard
 * RGB LED
 * 7x Jumper Wires
 * Button
 * Tilt Switch
 * 3x 330 ohm resistors (optional)

 This example code is in the public domain.
*/

// Connect Anode pin to VCC
// Connect Red to pin 19
// Connect Green to pin 17
// Connect Blue to pin 15
// Connect Button to pin 11
// Connect tilt switch to pin 11 in parallel to button.

#define RED 19
#define GREEN 17
#define BLUE 15

const int buttonPin = 11;

int redVal;
int greenVal;
int blueVal;

int delayTime = 10;

int breadboardButtonState; // variable for reading the BB button status


void setup() {
 pinMode(RED, OUTPUT);
 pinMode(GREEN, OUTPUT);
 pinMode(BLUE, OUTPUT);

 // 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);

  // initialize the onboard LED
  pinMode(RED_LED, OUTPUT);
  // initialize the breadboard push button pin as an input:
  pinMode(buttonPin, INPUT_PULLUP);
  // initialize the onboard pushbutton
  pinMode(PUSH2, INPUT_PULLUP);
}

/* In the loop function we will fade the brightness of the RGB LED
 * and simultaneously change the colors.
 */
void loop() {
 // We will use a for loop to change the color gradually
 // This will make it fade instead of instantly change
 // We need to go from 0 to 255. You may need to modify
 // your range depending on your LaunchPad to see a smooth
 // result.
 int PWM_RESOLUTION = 255; // this variable will hold our 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 );

 // read the state of the push button value:
 breadboardButtonState = digitalRead(buttonPin);
 
 // check if the breadboard push button is pressed.
 // if it is, turn the breadboard LED state HIGH
 if (breadboardButtonState == 0) {
   delayTime = 1;
 }
 else {
   delayTime = 10;
 }


 /* Fade 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

 delay( delayTime ); // wait for how long delay time is
 }

 // read the state of the push button value:
 breadboardButtonState = digitalRead(buttonPin);
 
 // check if the breadboard push button is pressed.
 // if it is, turn the breadboard LED state HIGH
 if (breadboardButtonState == 0) {
   delayTime = 1;
 }
 else {
   delayTime = 10;
 }


 /* Now full green */
 redVal = PWM_RESOLUTION; // max voltage will give us no color
 greenVal = 0; // zero voltage will give us full color
 blueVal = PWM_RESOLUTION; // max voltage will give us no color
 analogWrite( RED, redVal );
 analogWrite( GREEN, greenVal );
 analogWrite( BLUE, blueVal );

 // read the state of the push button value:
 breadboardButtonState = digitalRead(buttonPin);
 
 // check if the breadboard push button is pressed.
 // if it is, turn the breadboard LED state HIGH
 if (breadboardButtonState == 0) {
   delayTime = 1;
 }
 else {
   delayTime = 10;
 }


 // again we will use the for loop to change the color gradually
 /* Fade 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

 delay( delayTime ); // wait for how long delay time is
 }

 // read the state of the push button value:
 breadboardButtonState = digitalRead(buttonPin);
 
 // check if the breadboard push button is pressed.
 // if it is, turn the breadboard LED state HIGH
 if (breadboardButtonState == 0) {
   delayTime = 1;
 }
 else {
   delayTime = 10;
 }


 /* Now full 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 );

 // read the state of the push button value:
 breadboardButtonState = digitalRead(buttonPin);
 
 // check if the breadboard push button is pressed.
 // if it is, turn the breadboard LED state HIGH
 if (breadboardButtonState == 0) {
   delayTime = 1;
 }
 else {
   delayTime = 10;
 }


 // again we will use the for loop to change the color gradually
 /* Fade 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

 delay( delayTime ); // wait for how long delay time is
 }
}

Credits

Ryan Knightly
1 project • 5 followers
Contact
Antonio Caballero
1 project • 4 followers
Contact
Luis Leal
1 project • 3 followers
Contact
Kieren Boyd
1 project • 4 followers
Kieren Boyd
Contact
Adam Bobak
1 project • 3 followers
Contact
Oscar Reynozo
2 projects • 5 followers
Contact
Bill Qian
0 projects • 2 followers
Contact
Jose Mata Esqueda
0 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.