Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * *** Corvette Bumper Controller ***
- * Firmware 0.9 beta June 2020
- * by Michael Buch
- *
- * // Description:
- * Control of LED light in Corvette bumper decoration in Mom's Diner Burger Joint
- *
- * The overall voltage is 12VDC 5A to feed the Arduino Uno controller and a total of 180 led's on strips
- * LED Strips are controlled via 4 shift registers
- * 2x RGB is controlled by the 6 PWM pins
- * Just after this intro you can customize the 5 effects with the following commands
- * They are case sensitive!
- *
- * // Common effects:
- * AllOff(); // turns all lights off
- * delay(5000); // delay between effects 5000 = 5 sec.
- * delay(pottime); // delay set from the on board potentiometer 5 sec to 60 sec
- *
- * // Normal Car Effects
- * EngineOn(); // Engine On effect (ends with Normal driveing light on)
- * EngineOff(); // Engine Off effect (ends with All Off)
- * posistionlightOn(); // Normal driveing light on
- * posistionlightOff();// Normal driveing light off
- * breakOn(); // Press break
- * breakOff(); // Release break
- * TurnRight(10); // Turn Right 10 times = 10 sec
- * TurnLeft(5); // Turn Left 5 times = 5 sec
- * ThirdbreakOn(); // turns third break light on
- * ThirdbreakOff(); // turns third break light on
- * Hazard(10); // Hazzard light 10 times = 10 sec
- *
- * // Reverse lights:
- * revOn(); // turn on reverse light (as white as RGB can be :)
- * RGBOff(); // turn off both RGB/reverse lights
- * setLeftColor(50,150,250); // Turn on Left reverse light in a RGB color (0,0,0) turns it off
- * setRightColor(250,150,50); // Turn on Right reverse light in a RGB color - Max (255,255,255) = white'ish.
- *
- * //SPECIAL EFFECTS the effects takes time before next effect is running
- * rainbow(3); // Both RGB runs through 512 colors of the rainbow 3 times
- * USPolice(10); // Blue and Red police flash 10 times = 7 sec - Ends in RGB off
- * EUPolice(10); // Blue police flash 10 times = 7 sec - Ends in RGB off
- * USFire(10); // Red fire flash slow 10 times = 8 sec - Ends in RGB off
- * EUFire(10); // Blue fire flash slow 10 times = 8 sec - Ends in RGB off
- * FlashSidemarker(50); // Flash side markers 50 times - Ends in On state
- * Numberplatestrobe(50); // Numberplate Strobelight 50 times - Ends in On state
- * Redstrobe(5); // Red light under bunper Strobelight 5 times - Ends in On state
- *
- * // Third breaklight effects (the veriable "speed" is uses as a random speed/delay between 30ms and 100ms)
- * FlashEffect1(speed, 3); // speed of animation
- * FlashEffect2(speed, 3); // speed of animation
- * FlashEffect3(50, 20); // Kight Rider effect - speed(50 is good) and number of times to animate
- * FlashEffect4(speed, 3); // speed and times of animation
- * FlashEffect5(speed, 3); // speed of animation
- *
- *
- */
- // 1st User Effect (use commands from description)
- void effectA(int speed, int pottime){
- /*STRAT USER COMMANDS*/
- EngineOn();
- delay(pottime);
- Numberplatestrobe(50);
- delay(pottime);
- USFire(10);
- delay(1000);
- revOn();
- TurnLeft(5);
- delay(500);
- RGBOff();
- TurnLeft(5);
- delay(pottime);
- ThirdbreakOn();
- delay(10000);
- ThirdbreakOff();
- delay(pottime);
- rainbow(5);
- delay(pottime);
- USPolice(20);
- breakOn();
- USPolice(10);
- breakOff();
- USPolice(10);
- delay(pottime);
- FlashEffect1(speed, 3);
- delay(pottime);
- Hazard(20);
- delay(pottime);
- FlashEffect2(speed, 3);
- Redstrobe(50);
- delay(pottime);
- EngineOff();
- delay(pottime); // Time until next effect starts
- /*END USER COMMANDS*/
- }
- // 2nd User Effect (use commands from description)
- void effectB(int speed, int pottime){
- /*STRAT USER COMMANDS*/
- EngineOn();
- delay(5000);
- breakOn();
- delay(1500);
- revOn();
- delay(1500);
- breakOff();
- delay(10000);
- breakOn();
- delay(3000);
- RGBOff();
- delay(2000);
- breakOff();
- delay(pottime);
- TurnLeft(2);
- breakOn();
- TurnLeft(10);
- breakOff();
- TurnLeft(5);
- delay(pottime);
- FlashEffect3(50, 20); //Night rider @ 50ms 10 times
- delay(pottime);
- breakOn();
- delay(10000);
- breakOff();
- delay(pottime);
- TurnRight(2);
- breakOn();
- TurnRight(10);
- breakOff();
- TurnRight(5);
- delay(pottime);
- rainbow(10);
- delay(pottime);
- FlashEffect4(speed, 10);
- delay(pottime);
- breakOn();
- TurnRight(10);
- delay(5000);
- breakOff();
- delay(5000);
- rainbow(5);
- delay(10000);
- EngineOff();
- delay(pottime); // Time until next effect starts
- /*END USER COMMANDS*/
- }
- // 3rd User Effect (use commands from description)
- void effectC(int speed, int pottime){
- /*STRAT USER COMMANDS*/
- EngineOn();
- delay(5000);
- breakOn();
- delay(2000);
- TurnLeft(2);
- breakOff();
- TurnLeft(6);
- delay(pottime);
- USPolice(10);
- breakOn();
- USPolice(10);
- breakOff();
- USPolice(5);
- delay(pottime);
- TurnLeft(2);
- breakOff();
- TurnLeft(6);
- delay(30000);
- rainbow(5);
- delay(30000);
- FlashEffect1(speed, 10);
- delay(pottime);
- breakOn();
- TurnRight(10);
- delay(5000);
- breakOff();
- delay(pottime);
- breakOn();
- delay(7000);
- revOn();
- delay(2000);
- breakOff();
- delay(6000);
- breakOn();
- delay(1000);
- RGBOff();
- delay(1000);
- breakOff();
- TurnLeft(6);
- EUPolice(20);
- delay(pottime);
- breakOn();
- delay(10000);
- breakOff();
- delay(pottime);
- Numberplatestrobe(70);
- delay(pottime);
- breakOn();
- TurnRight(10);
- breakOff();
- TurnRight(2);
- breakOn();
- TurnRight(3);
- breakOff();
- delay(5000);
- EngineOff();
- delay(pottime); // Time until next effect starts
- /*END USER COMMANDS*/
- }
- // 4th User Effect (use commands from description)
- void effectD(int speed, int pottime){
- /*STRAT USER COMMANDS*/
- delay(5000);
- FlashEffect3(50, 1); //Night rider @ 50ms 1 times
- delay(5000);
- FlashEffect3(50, 1); //Night rider @ 50ms 1 times
- delay(5000);
- Redstrobe(50);
- FlashEffect3(50, 20); //Night rider @ 50ms 20 times
- EngineOn();
- delay(pottime);
- FlashSidemarker(50);
- delay(pottime);
- FlashEffect1(speed, 10);
- delay(pottime);
- FlashEffect2(speed, 10);
- delay(pottime);
- Hazard(20);
- delay(3000);
- EngineOff();
- delay(pottime); // Time until next effect starts
- /*END USER COMMANDS*/
- }
- // 5th User Effect (use commands from description)
- void effectE(int speed, int pottime){
- /*STRAT USER COMMANDS*/
- EUPolice(20);
- delay(5000);
- EngineOn();
- delay(pottime);
- rainbow(5);
- delay(pottime);
- Hazard(20);
- delay(pottime);
- posistionlightOff();
- delay(2000);
- FlashSidemarker(50);
- Numberplatestrobe(50);
- Redstrobe(50);
- delay(2000);
- posistionlightOn();
- delay(pottime);
- EngineOff();
- delay(pottime); // Time until next effect starts
- /*END USER COMMANDS*/
- }
- /*
- * WARNING!!
- * Below is the code to make the above work
- * change at own rick :)
- */
- /* START PROGRAM */
- // Define Constants and Pin Setup
- int AUX1 = 2; // Spare Output
- int LR = 3; // PWM for Left side RGB led (Red)
- int AUX2 = 4; // Spare Output
- int LG = 5; // PWM for Left side RGB led (Green)
- int LB = 6; // PWM for Left side RGB led (Blue)
- int latchPin = 7; // Latch pin of 74HC595 is connected to Digital pin 2
- int clockPin = 8; // Clock pin 11 of 74HC595 is connected to Digital pin 6
- int RR = 9; // PWM for Right side RGB led (Red)
- int RG = 10; // PWM for Right side RGB led (Green)
- int RB = 11; // PWM for Right side RGB led (Blue)
- int dataPin = 12; // Data pin 14 of 74HC595 is connected to Digital pin 5
- int statusled = 13; // test/status led
- int pot = 0; // Potmeter on PCB for speed ajustment
- int numColors = 512; // Used in the rainbow effect
- // Define Veriables
- byte* registerState; // Byte to send
- int effectId = 0; // effect id for random effects
- int prevEffect = 0; // prev. effect id for random effects
- int effectRepeat = 0; // repeat for random effects
- int effectSpeed = 30; // speed in ms for random effects
- int potval = 0; // on board pot used for delay time
- int LRed = 255; // can be used for the left side red color
- int LGreen = 255; // can be used for the left side green color
- int LBlue = 255; // can be used for the left side blue color
- int RRed = 255; // can be used for the right side red color
- int RGreen = 255; // can be used for the right side green color
- int RBlue = 255; // can be used for the right side blue color
- int counter = 0; // Used in the rainbow effect
- int animationDelay = 10; // // Used in the rainbow effect
- // Setup micro controller
- void setup() {
- //Initialize byte array to send to shift registers
- registerState = new byte[4];
- for (size_t i = 0; i < 4; i++) {
- registerState[i] = 0;
- }
- //set pins to output to control the shift registers
- pinMode(latchPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- //set pins to output pwm control the 2 x RGB lights
- pinMode(LR, OUTPUT);
- pinMode(LG, OUTPUT);
- pinMode(LB, OUTPUT);
- pinMode(RR, OUTPUT);
- pinMode(RG, OUTPUT);
- pinMode(RB, OUTPUT);
- //set pins to output for Digital outs
- pinMode(AUX1, OUTPUT);
- pinMode(AUX2, OUTPUT);
- // Start serial to display effect names running
- Serial.begin(9600);
- AllOff();
- // Show credits and version
- Serial.println("");
- Serial.println("*** Covette Bumper Controller ***");
- Serial.println(" Firmware 0.9 beta June 2020");
- Serial.println(" by Michael Buch");
- Serial.println("");
- Serial.println(" <<< Program Running >>>");
- Serial.println("");
- }
- // Start The Loop
- void loop(){
- do{
- effectId = random(1, 5); // Let's find a random effect
- }
- while (effectId == prevEffect);
- prevEffect = effectId;
- switch (effectId){
- case 1:
- effectRepeat = random(1, 4); // How many times to repeat effect 1
- break;
- case 2:
- effectRepeat = random(1, 4); // How many times to repeat effect 2
- break;
- case 3:
- effectRepeat = random(1, 4); // How many times to repeat effect 3
- break;
- case 4:
- effectRepeat = random(1, 4); // How many times to repeat effect 4
- break;
- case 5:
- effectRepeat = random(1, 4); // How many times to repeat effect 5
- break;
- }
- for (int i = 1; i <= effectRepeat; i++) { // Repeat the effect
- potval = analogRead(pot);
- int pottime = map(potval, 0, 1023, 5000, 60000);
- if (pottime < 0) {
- pottime = pottime * (-1);
- }
- effectSpeed = random(10, 100); // Random speed for some effects
- switch (effectId){
- case 1:
- Serial.print("Effect A running: ");Serial.print(i);Serial.print(" of ");Serial.println(effectRepeat);
- Serial.print(" Annimation delay = ");Serial.println(effectSpeed);
- Serial.print(" Effect delay = ");Serial.println(pottime);
- effectA(effectSpeed, pottime);
- break;
- case 2:
- Serial.print("Effect B running: ");Serial.print(i);Serial.print(" of ");Serial.println(effectRepeat);
- Serial.print(" Annimation delay = ");Serial.println(effectSpeed);
- Serial.print(" Effect delay = ");Serial.println(pottime);
- effectB(effectSpeed, pottime);
- break;
- case 3:
- Serial.print("Effect C running: ");Serial.print(i);Serial.print(" of ");Serial.println(effectRepeat);
- Serial.print(" Annimation delay = ");Serial.println(effectSpeed);
- Serial.print(" Effect delay = ");Serial.println(pottime);
- effectC(effectSpeed, pottime);
- break;
- case 4:
- Serial.print("Effect D running: ");Serial.print(i);Serial.print(" of ");Serial.println(effectRepeat);
- Serial.print(" Annimation delay = ");Serial.println(effectSpeed);
- Serial.print(" Effect delay = ");Serial.println(pottime);
- effectD(effectSpeed, pottime);
- break;
- case 5:
- Serial.print("Effect E running: ");Serial.print(i);Serial.print(" of ");Serial.println(effectRepeat);
- Serial.print(" Annimation delay = ");Serial.println(effectSpeed);
- Serial.print(" Effect delay = ");Serial.println(pottime);
- effectE(effectSpeed, pottime);
- break;
- }
- }
- }
- // Write to the shift register
- void regWrite(int pin, bool state){
- //Determines register
- int reg = pin / 8;
- //Determines pin for actual register
- int actualPin = pin - (8 * reg);
- //Begin session
- digitalWrite(latchPin, LOW);
- for (int i = 0; i < 4; i++){
- //Get actual states for register
- byte* states = ®isterState[i];
- //Update state
- if (i == reg){
- bitWrite(*states, actualPin, state);
- }
- //Write
- shiftOut(dataPin, clockPin, LSBFIRST, *states);
- }
- //End session
- digitalWrite(latchPin, HIGH);
- }
- /* START EFFECTS*/
- // All off
- void AllOff(){
- for (int k = 0; k <= 31; k++){
- regWrite(k, LOW);
- }
- RGBOff();
- }
- // Third break light off
- void ThirdbreakOff(){
- for (int i = 23; i >= 8; i--){
- regWrite(i, LOW);
- }
- }
- // Third break light on
- void ThirdbreakOn(){
- for (int i = 23; i >= 8; i--){
- regWrite(i, HIGH);
- }
- }
- // Posistion light on
- void posistionlightOn(){
- regWrite(0, HIGH);
- regWrite(2, HIGH);
- regWrite(5, HIGH);
- regWrite(7, HIGH);
- regWrite(24, HIGH);
- regWrite(26, HIGH);
- regWrite(29, HIGH);
- regWrite(31, HIGH);
- }
- // Posistion light off
- void posistionlightOff(){
- regWrite(0, LOW);
- regWrite(2, LOW);
- regWrite(5, LOW);
- regWrite(7, LOW);
- regWrite(24, LOW);
- regWrite(26, LOW);
- regWrite(29, LOW);
- regWrite(31, LOW);
- }
- // Break light on
- void breakOn(){
- regWrite(4, HIGH);
- regWrite(6, HIGH);
- regWrite(25, HIGH);
- regWrite(27, HIGH);
- ThirdbreakOn();
- }
- // Break light off
- void breakOff(){
- regWrite(4, LOW);
- regWrite(6, LOW);
- regWrite(25, LOW);
- regWrite(27, LOW);
- ThirdbreakOff();
- }
- // Reverse on
- void revOn(){
- setLeftColor(255,255,255);
- setRightColor(255,255,255);
- }
- // RGB off
- void RGBOff(){
- setLeftColor(0,0,0);
- setRightColor(0,0,0);
- }
- // Turn Left
- void TurnLeft(int times){
- for (int i = 0; i <= times; i++){
- regWrite(30, HIGH);
- regWrite(28, HIGH);
- delay(500);
- regWrite(30, LOW);
- regWrite(28, LOW);
- delay(500);
- }
- }
- // Turn Right
- void TurnRight(int times){
- for (int i = 0; i <= times; i++){
- regWrite(1, HIGH);
- regWrite(3, HIGH);
- delay(500);
- regWrite(1, LOW);
- regWrite(3, LOW);
- delay(500);
- }
- }
- // Hazard Light
- void Hazard(int times){
- for (int i = 0; i <= times; i++){
- regWrite(1, HIGH);
- regWrite(3, HIGH);
- regWrite(30, HIGH);
- regWrite(28, HIGH);
- delay(500);
- regWrite(30, LOW);
- regWrite(28, LOW);
- regWrite(1, LOW);
- regWrite(3, LOW);
- delay(500);
- }
- }
- // Engine on (start up)
- void EngineOn(){
- regWrite(3, HIGH);
- regWrite(6, HIGH);
- regWrite(25, HIGH);
- regWrite(28, HIGH);
- delay(500);
- regWrite(2, HIGH);
- regWrite(5, HIGH);
- regWrite(26, HIGH);
- regWrite(29, HIGH);
- delay(500);
- regWrite(1, HIGH);
- regWrite(4, HIGH);
- regWrite(27, HIGH);
- regWrite(30, HIGH);
- delay(300);
- FlashEffect4(30, 1);
- regWrite(3, LOW);
- regWrite(6, LOW);
- regWrite(25, LOW);
- regWrite(28, LOW);
- regWrite(2, LOW);
- regWrite(5, LOW);
- regWrite(26, LOW);
- regWrite(29, LOW);
- regWrite(1, LOW);
- regWrite(4, LOW);
- regWrite(27, LOW);
- regWrite(30, LOW);
- delay(400);
- posistionlightOn();
- }
- // Engine off (shot down)
- void EngineOff(){
- AllOff();
- ThirdbreakOn();
- regWrite(3, HIGH);
- regWrite(6, HIGH);
- regWrite(25, HIGH);
- regWrite(28, HIGH);
- regWrite(2, HIGH);
- regWrite(5, HIGH);
- regWrite(26, HIGH);
- regWrite(29, HIGH);
- regWrite(1, HIGH);
- regWrite(4, HIGH);
- regWrite(27, HIGH);
- regWrite(30, HIGH);
- delay(300);
- for (int k = 16; k <= 23; k++){
- delay(100);
- regWrite(k, LOW);
- regWrite(31 - k, LOW);
- }
- delay(300);
- regWrite(1, LOW);
- regWrite(4, LOW);
- regWrite(27, LOW);
- regWrite(30, LOW);
- delay(500);
- regWrite(2, LOW);
- regWrite(5, LOW);
- regWrite(26, LOW);
- regWrite(29, LOW);
- delay(500);
- regWrite(3, LOW);
- regWrite(6, LOW);
- regWrite(25, LOW);
- regWrite(28, LOW);
- AllOff();
- }
- // Numberplate strobe Light
- void Numberplatestrobe(int strobe){
- for (int i = 0; i <= strobe; i++){
- regWrite(7, LOW);
- delay(30);
- regWrite(7, HIGH);
- delay(30);
- }
- }
- // Red strobe Light
- void Redstrobe(int strobe){
- for (int i = 0; i <= strobe; i++){
- regWrite(24, LOW);
- delay(30);
- regWrite(24, HIGH);
- delay(30);
- }
- }
- // Flash side marker lights
- void FlashSidemarker(int times){
- for (int i = 0; i <= times; i++){
- regWrite(0, LOW);
- regWrite(31, LOW);
- delay(400);
- regWrite(0, HIGH);
- regWrite(31, HIGH);
- delay(50);
- regWrite(0, LOW);
- regWrite(31, LOW);
- delay(50);
- regWrite(0, HIGH);
- regWrite(31, HIGH);
- delay(50);
- }
- }
- // US Police effect
- void USPolice(int times){
- RGBOff();
- for (int i = 0; i <= times; i++){
- setRightColor(255,0,0);
- delay(100);
- setRightColor(0,0,0);
- delay(100);
- setRightColor(255,0,0);
- delay(100);
- setRightColor(0,0,0);
- delay(100);
- setLeftColor(0,0,255);
- delay(100);
- analogWrite(LB, 0);
- delay(100);
- analogWrite(LB, 255);
- delay(100);
- analogWrite(LB, 0);
- }
- }
- // US Fire effect
- void USFire(int times){
- RGBOff();
- for (int i = 0; i <= times; i++){
- analogWrite(RR, 255);
- analogWrite(LR, 0);
- delay(400);
- analogWrite(LR, 255);
- analogWrite(RR, 0);
- delay(400);
- }
- RGBOff();
- }
- // EU Police effect
- void EUPolice(int times){
- RGBOff();
- for (int i = 0; i <= times; i++){
- analogWrite(RB, 255);
- delay(100);
- analogWrite(RB, 0);
- delay(100);
- analogWrite(RB, 255);
- delay(100);
- analogWrite(RB, 0);
- delay(100);
- analogWrite(LB, 255);
- delay(100);
- analogWrite(LB, 0);
- delay(100);
- analogWrite(LB, 255);
- delay(100);
- analogWrite(LB, 0);
- }
- }
- // EU Fire effect
- void EUFire(int times){
- RGBOff();
- for (int i = 0; i <= times; i++){
- analogWrite(RB, 255);
- analogWrite(LB, 0);
- delay(400);
- analogWrite(LB, 255);
- analogWrite(RB, 0);
- delay(400);
- }
- RGBOff();
- }
- // RGB rainbow
- void rainbow(int repeat){
- for(int r = 0; r <= repeat; r++){
- for(int i = 0; i <= numColors; i++){
- float colorNumber = counter > numColors ? counter - numColors: counter;
- float saturation = 1; // Between 0 and 1 (0 = gray, 1 = full color)
- float brightness = 1; // Between 0 and 1 (0 = dark, 1 is full brightness)
- float hue = (colorNumber / float(numColors)) * 360; // Number between 0 and 360
- long color = HSBtoRGB(hue, saturation, brightness);
- int red = color >> 16 & 255;
- int green = color >> 8 & 255;
- int blue = color & 255;
- setLeftColor(red, green, blue);
- setRightColor(red, green, blue);
- counter = (counter + 1) % (numColors * 2);
- delay(animationDelay);
- }
- }
- RGBOff();
- }
- // 1st Flash Effect
- void FlashEffect1(int speed, int repeat){
- for (int r = 1; r <= repeat; r++){
- for (int i = 8; i < 24; i++){
- for (int k = i; k < 24; k++){
- regWrite(k, HIGH);
- delay(speed);
- regWrite(k, LOW);
- }
- regWrite(i, HIGH);
- }
- delay(speed * 5);
- for (int i = 23; i >= 8; i--){
- regWrite(i, LOW);
- }
- }
- delay(speed * 5);
- ThirdbreakOff();
- }
- // 2nd Flash Effect
- void FlashEffect2(int speed, int repeat){
- for (int r = 1; r <= repeat; r++){
- for (int i = 23; i >= 8; i--){
- for (int k = 8; k < i; k++){
- regWrite(k, HIGH);
- delay(speed);
- regWrite(k, LOW);
- }
- regWrite(i, HIGH);
- }
- delay(speed * 5);
- for (int i = 23; i >= 8; i--){
- regWrite(i, LOW);
- }
- }
- delay(speed * 5);
- ThirdbreakOff();
- }
- // 3rd Flash Effect (knight rider)
- void FlashEffect3(int speed, int repeat){
- for (int r = 1; r <= repeat; r++){
- int prevI = 8;
- for (int i = 8; i < 24; i++){
- regWrite(prevI, LOW);
- regWrite(i, HIGH);
- prevI = i;
- delay(speed);
- }
- for (int i = 23; i >= 8; i--){
- regWrite(prevI, LOW);
- regWrite(i, HIGH);
- prevI = i;
- delay(speed);
- }
- //delay(speed * 5);
- for (int i = 23; i >= 8; i--){
- regWrite(i, LOW);
- }
- }
- delay(1000);
- ThirdbreakOff();
- }
- // 4th Flash Effect
- void FlashEffect4(int speed, int repeat){
- for (int r = 1; r <= repeat; r++){
- for (int i = 8; i < 16; i++){
- for (int k = i; k < 16; k++){
- regWrite(k, HIGH);
- regWrite(31 - k, HIGH);
- delay(speed);
- regWrite(k, LOW);
- regWrite(31 - k, LOW);
- }
- regWrite(i, HIGH);
- regWrite(31 - i, HIGH);
- }
- delay(speed * 5);
- for (int i = 23; i >= 8; i--){
- regWrite(i, LOW);
- }
- }
- delay(speed * 5);
- ThirdbreakOff();
- }
- // 5th Flash Effect
- void FlashEffect5(int speed, int repeat){
- for (int r = 1; r <= repeat; r++){
- for (int i = 23; i >= 16; i--){
- for (int k = 16; k <= i; k++){
- regWrite(k, HIGH);
- regWrite(31 - k, HIGH);
- delay(speed);
- regWrite(k, LOW);
- regWrite(31 - k, LOW);
- }
- regWrite(i, HIGH);
- regWrite(31 - i, HIGH);
- }
- delay(speed * 5);
- }
- delay(speed * 5);
- ThirdbreakOff();
- }
- // Set the color of the left reverse light
- void setLeftColor (unsigned char red, unsigned char green, unsigned char blue){
- analogWrite(LR, red);
- analogWrite(LG, green);
- analogWrite(LB, blue);
- }
- // Set the color of the left reverse light
- void setRightColor (unsigned char red, unsigned char green, unsigned char blue){
- analogWrite(RR, red);
- analogWrite(RG, green);
- analogWrite(RB, blue);
- }
- // Convert Hue, Sat and brightness to RGB - Used in rainbow effect
- long HSBtoRGB(float _hue, float _sat, float _brightness) {
- float red = 0.0;
- float green = 0.0;
- float blue = 0.0;
- if (_sat == 0.0) {
- red = _brightness;
- green = _brightness;
- blue = _brightness;
- } else {
- if (_hue == 360.0) {
- _hue = 0;
- }
- int slice = _hue / 60.0;
- float hue_frac = (_hue / 60.0) - slice;
- float aa = _brightness * (1.0 - _sat);
- float bb = _brightness * (1.0 - _sat * hue_frac);
- float cc = _brightness * (1.0 - _sat * (1.0 - hue_frac));
- switch(slice) {
- case 0:
- red = _brightness;
- green = cc;
- blue = aa;
- break;
- case 1:
- red = bb;
- green = _brightness;
- blue = aa;
- break;
- case 2:
- red = aa;
- green = _brightness;
- blue = cc;
- break;
- case 3:
- red = aa;
- green = bb;
- blue = _brightness;
- break;
- case 4:
- red = cc;
- green = aa;
- blue = _brightness;
- break;
- case 5:
- red = _brightness;
- green = aa;
- blue = bb;
- break;
- default:
- red = 0.0;
- green = 0.0;
- blue = 0.0;
- break;
- }
- }
- long ired = red * 255.0;
- long igreen = green * 255.0;
- long iblue = blue * 255.0;
- return long((ired << 16) | (igreen << 8) | (iblue));
- }
- /* END PROGRAM */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement