Oland Carter - ojc1Alonzoz Diaz (ad81)
Published

Fading Lights

Creating an LED that makes aesthetic lights in these dark times--Join us on this journey of electrical engineering (aka "MAGIC")

BeginnerFull instructions provided474
Fading Lights

Things used in this project

Story

Read more

Schematics

Pin Maps

This is a pin map for the launch pad we were using, and it allowed us to figure out how all of our materials were to fit together on the launchpad.

Breadboard and Launchpad Schematics

This shows what the breadboard and launchpad looked like so that others can replicate our experiment.

Breadboard and Launchpad Schematics

This shows what the breadboard and launchpad looked like so others can replicate our work.

Breadboard and Launchpad Schematics

This shows what the breadboard and launchpad looked like so others can replicate our work.

Rough actual schematic

This designates the positions on an actual tiva-c launchpad and breadboard.

Code

Fading Lights Code

C/C++
This is our code to run the Fade RGB LED with multiple colors and involving a tilt switch
/*

 Credits to Example 01: Fade RGB LED (PWM) from Energia 
*/

// #define to rename our pins from numbers to readable variables
#define RED 19 
#define GREEN 38 
#define BLUE 31
#define delayTime 10 


int redVal;
int greenVal;
int blueVal;


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

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

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

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

 // 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
 }

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

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

Oland Carter - ojc1
1 project • 1 follower
Alonzoz Diaz (ad81)
1 project • 1 follower

Comments