**CUBE CODE** Red Blue Emergengy Flashing

The "Cube4" is a 4x4x4 RGB LED cube with an Arduino Leonardo compatible onboard controller. [Product page]
Post Reply
yatto
Posts:5
Joined:Wed Jan 06, 2016 3:58 pm
**CUBE CODE** Red Blue Emergengy Flashing

Post by yatto » Fri Jan 22, 2016 2:16 pm

Hi guys

Bought this kit for my 11 year old and I to build and get a taste for electronics and coding. Absolutely loved it, and it works a treat. So we wanted to try our first Sketch, bare in mind we (I) have never done any sort of coding before, so I am sure there are better ways of achieving what we did but it seems to work ok. Our first attempt was to try and replicate the Red Blue flashing of emergency lights. End result is ok. If anyone has any tips for simplifying the Sketch please feel free to share

Code: Select all

#include "SPI.h"
#include "Cube.h"

int timer=500.0;
int timer2=50.0;
int timer3=350;
int timer4=125;

Cube cube;

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

//Fast Flash

      cube.setplane(X, 0, RED);
      cube.setplane(X, 1, RED);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);
      cube.setplane(X, 0, RED);
      cube.setplane(X, 1, RED);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);
      cube.setplane(X, 0, RED);
      cube.setplane(X, 1, RED);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);

      cube.all (BLACK);
      delay (timer2);

      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLUE);
      cube.setplane(X, 3, BLUE);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLUE);
      cube.setplane(X, 3, BLUE);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLUE);
      cube.setplane(X, 3, BLUE);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);

      cube.all (BLACK);
      delay (timer2);
      
      cube.setplane(X, 0, RED);
      cube.setplane(X, 1, RED);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);
      cube.setplane(X, 0, RED);
      cube.setplane(X, 1, RED);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);
      cube.setplane(X, 0, RED);
      cube.setplane(X, 1, RED);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);

      cube.all (BLACK);
      delay (timer2);

      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLUE);
      cube.setplane(X, 3, BLUE);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLUE);
      cube.setplane(X, 3, BLUE);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLUE);
      cube.setplane(X, 3, BLUE);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);

      cube.all (BLACK);
      delay (timer2);

      cube.setplane(X, 0, RED);
      cube.setplane(X, 1, RED);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);
      cube.setplane(X, 0, RED);
      cube.setplane(X, 1, RED);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);
      cube.setplane(X, 0, RED);
      cube.setplane(X, 1, RED);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);

      cube.all (BLACK);
      delay (timer2);
      
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLUE);
      cube.setplane(X, 3, BLUE);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLUE);
      cube.setplane(X, 3, BLUE);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLUE);
      cube.setplane(X, 3, BLUE);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);

      cube.all (BLACK);
      delay (timer2);

      cube.setplane(X, 0, RED);
      cube.setplane(X, 1, RED);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);
      cube.setplane(X, 0, RED);
      cube.setplane(X, 1, RED);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);
      cube.setplane(X, 0, RED);
      cube.setplane(X, 1, RED);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);

      cube.all (BLACK);
      delay (timer2);
      
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLUE);
      cube.setplane(X, 3, BLUE);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLUE);
      cube.setplane(X, 3, BLUE);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLUE);
      cube.setplane(X, 3, BLUE);
      delay(timer2);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay (timer2);

      cube.all (BLACK);
      delay (timer2);

//Slow Flash

      cube.setplane(X, 0, RED);
      cube.setplane(X, 1, RED);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay(timer3);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLUE);
      cube.setplane(X, 3, BLUE);
      delay(timer3);
      cube.setplane(X, 0, RED);
      cube.setplane(X, 1, RED);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay(timer3);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLUE);
      cube.setplane(X, 3, BLUE);
      delay(timer3);
      cube.setplane(X, 0, RED);
      cube.setplane(X, 1, RED);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay(timer3);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLUE);
      cube.setplane(X, 3, BLUE);
      delay(timer3);
      cube.setplane(X, 0, RED);
      cube.setplane(X, 1, RED);
      cube.setplane(X, 2, BLACK);
      cube.setplane(X, 3, BLACK);
      delay(timer3);
      cube.setplane(X, 0, BLACK);
      cube.setplane(X, 1, BLACK);
      cube.setplane(X, 2, BLUE);
      cube.setplane(X, 3, BLUE);
      delay(timer3);
          
          
      
      
      }

yatto
Posts:5
Joined:Wed Jan 06, 2016 3:58 pm

Re: **CUBE CODE** Red Blue Emergengy Flashing

Post by yatto » Tue Jan 26, 2016 11:45 am

Thanks neographophobic, that's awesome, exactly what I was hoping for

Post Reply