** CUBE CODE ** RAINBOW FADER

The "Cube4" is a 4x4x4 RGB LED cube with an Arduino Leonardo compatible onboard controller. [Product page]
Post Reply
sparky-nz
Posts: 25
Joined: Wed Oct 02, 2013 9:16 pm

** CUBE CODE ** RAINBOW FADER

Post by sparky-nz » Wed Oct 09, 2013 10:12 am

HIYA

This one is entirely down to my son Thomas the Coding Guru LOL

The sketch will fade from red through to white using the PLANES of the cube from right to left.

THINGS TO TRY
Change direction to left to right by changing all the + to + and all the - to +
Change fade speed byte timer=3

HAVE FUN

Code: Select all

 /*
 * File:    rainbow 1
 * Version: 1.0
 * Author:  THOMAS
 
 */

#include "SPI.h"
#include "Cube.h"
byte r0=255;
byte b0=0;
byte g0=0;
byte r1=0;
byte b1=255;
byte g1=0;
byte r2=0;
byte b2=0;
byte g2=255;
byte r3=255;
byte b3=255;
byte g3=255;
byte t=0;
byte timer=3;


  
Cube cube;

void setup(void) {
   cube.begin(0, 115200); // Start on serial port 0 (USB) at 115200 baud
}

void loop(void) {

 while(t<255){
   r0=r0-1;
   b0=b0+1;
   b1=b1-1;
   g1=g1+1;
   r2=r2+1;
   b2=b2+1;
   b3=b3-1;
   g3=g3-1;
   t=t+1;
   
   cube.setplane(X,0,RGB(r0,g0,b0));
   cube.setplane(X,1,RGB(r1,g1,b1));
   cube.setplane(X,2,RGB(r2,g2,b2));
   cube.setplane(X,3,RGB(r3,g3,b3));
   delay(timer);
 }
 
 t=0;
 while(t<255){
   r3=r3-1;
   b3=b3+1;
   b0=b0-1;
   g0=g0+1;
   r1=r1+1;
   b1=b1+1;
   b2=b2-1;
   g2=g2-1;
   t=t+1;
   
   cube.setplane(X,0,RGB(r0,g0,b0));
   cube.setplane(X,1,RGB(r1,g1,b1));
   cube.setplane(X,2,RGB(r2,g2,b2));
   cube.setplane(X,3,RGB(r3,g3,b3));
   delay(timer);
 }
 t=0;
 while(t<255){
   r2=r2-1;
   b2=b2+1;
   b3=b3-1;
   g3=g3+1;
   r0=r0+1;
   b0=b0+1;
   b1=b1-1;
   g1=g1-1;
   t=t+1;
   
   cube.setplane(X,0,RGB(r0,g0,b0));
   cube.setplane(X,1,RGB(r1,g1,b1));
   cube.setplane(X,2,RGB(r2,g2,b2));
   cube.setplane(X,3,RGB(r3,g3,b3));
   delay(timer);
 }
 t=0;
 while(t<255){
   r1=r1-1;
   b1=b1+1;
   b2=b2-1;
   g2=g2+1;
   r3=r3+1;
   b3=b3+1;
   b0=b0-1;
   g0=g0-1;
   t=t+1;
   
   cube.setplane(X,0,RGB(r0,g0,b0));
   cube.setplane(X,1,RGB(r1,g1,b1));
   cube.setplane(X,2,RGB(r2,g2,b2));
   cube.setplane(X,3,RGB(r3,g3,b3));
   delay(timer);
 }
 t=0; 
  
}

Post Reply