概述
/*
The 8x8x8 RGB LED Cube
by Kevin Darrah
www.kevindarrah.com
kevin@kevindarrah.com
Latest
V12 04/17/2013
Release Notes:
V11
- Fixed bug with BAM timing
- Moved Blank pin setup to ISR so pins are dead until they are written to
V12
bitwise operation to set pins LOW was incorrect
should be PORTx &= ~(1<<pinNumber);
Disclaimer:
Not a professional LED cube builder, this is how I did it, and this is my cube
*/
#include <SPI.h>// SPI Library used to clock data out to the shift registers
#define latch_pin 44// can use any pin you want to latch the shift registers
#define blank_pin 45// same, can use any pin you want for this, just make sure you pull up via a 1k to 5V
#define data_pin 51// used by SPI, must be pin 11
#define clock_pin 52// used by SPI, must be 13
//***variables***variables***variables***variables***variables***variables***variables***variables
//These variables are used by multiplexing and Bit Angle Modulation Code
int shift_out;//used in the code a lot in for(i= type loops
byte anode[8];//byte to write to the anode shift register, 8 of them, shifting the ON level in each byte in the array
//This is how the brightness for every LED is stored,
//Each LED only needs a 'bit' to know if it should be ON or OFF, so 64 Bytes gives you 512 bits= 512 LEDs
//Since we are modulating the LEDs, using 4 bit resolution, each color has 4 arrays containing 64 bits each
byte red0[64], red1[64], red2[64], red3[64];
byte blue0[64], blue1[64], blue2[64], blue3[64];
byte green0[64], green1[64], green2[64], green3[64];
//notice how more resolution will eat up more of your precious RAM
int level=0;//keeps track of which level we are shifting data to
int anodelevel=0;//this increments through the anode levels
int BAM_Bit, BAM_Counter=0; // Bit Angle Modulation variables to keep track of things
//These variables can be used for other things
unsigned long start;//for a millis timer to cycle through the animations
int globalRed, globalGreen, globalBlue;
byte messageDrawScrollArray[15];
// Lets see if we can store this in ram??
byte array_ASCII[128][5] = {
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 0
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 1
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 2
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 3
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 4
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 5
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 6
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 7
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 8
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 9
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 10
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 11
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 12
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 13
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 14
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 15
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 16
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 17
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 18
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 19
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 20
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 21
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 22
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 23
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 24
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 25
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 26
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 27
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 28
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 29
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 30
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 31
{0x00, 0x00, 0x00, 0x00, 0x00}, // Space = Space, ACSII 32
{0x00, 0x00, 0xF9, 0x00, 0x00}, // ! = !, ACSII 33
{0x00, 0xE0, 0x00, 0xE0, 0x00}, // “ = ", ACSII 34
{0x24, 0xFF, 0x24, 0xFF, 0x24}, // # = Hash Tag, ACSII 35
{0x12, 0x2A, 0x7F, 0x2A, 0x24}, // $ = $, ACSII 36
{0x62, 0x64, 0x08, 0x13, 0x23}, // % = %, ACSII 37
{0x76, 0x89, 0x95, 0x62, 0x05}, // & = &, ACSII 38
{0x00, 0xC0, 0x80, 0x00, 0x00}, // ‘ = ', ACSII 39
{0x00, 0x3C, 0x42, 0x81, 0x00}, // ( = (, ACSII 40
{0x00, 0x81, 0x42, 0x3C, 0x00}, // ) = ), ACSII 41
{0x44, 0x28, 0xFE, 0x28, 0x44}, // * = *, ACSII 42
{0x08, 0x08, 0x3E, 0x08, 0x08}, // "+" = +, ACSII 43
{0x00, 0x05, 0x06, 0x00, 0x00}, // , = ,, ACSII 44
{0x08, 0x08, 0x08, 0x08, 0x08}, // - = -, ACSII 45
{0x00, 0x03, 0x03, 0x00, 0x00}, // . = ., ACSII 46
{0x01, 0x02, 0x04, 0x08, 0x10}, // / = /, ACSII 47
{0x7E, 0x89, 0x91, 0xA1, 0x7E}, // 0 = 0, ACSII 48
{0x00, 0x41, 0xFF, 0x01, 0x00}, // 1 = 1, ACSII 49
{0x43, 0x85, 0x89, 0x91, 0x61}, // 2 = 2, ACSII 50
{0x42, 0x81, 0x91, 0x91, 0x6E}, // 3 = 3, ACSII 51
{0x18, 0x28, 0x48, 0xFF, 0x08}, // 4 = 4, ACSII 52
{0xF2, 0x91, 0x91, 0x91, 0x8E}, // 5 = 5, ACSII 53
{0x1E, 0x29, 0x49, 0x89, 0x86}, // 6 = 6, ACSII 54
{0x80, 0x8F, 0x90, 0xA0, 0xC0}, // 7 = 7, ACSII 55
{0x6E, 0x91, 0x91, 0x91, 0x6E}, // 8 = 8, ACSII 56
{0x70, 0x89, 0x89, 0x8A, 0x7C}, // 9 = 9, ACSII 57
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = :, ACSII 58
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = ;, ACSII 59
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = <, ACSII 60
{0x14, 0x14, 0x14, 0x14, 0x14}, // = = =, ACSII 61
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = >, ACSII 62
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = ?, ACSII 63
{0x66, 0x89, 0x8F, 0x81, 0x7E}, // @ = @, ACSII 64
{0x7F, 0x88, 0x88, 0x88, 0x7F}, // A = A, ACSII 65
{0xFF, 0x91, 0x91, 0x91, 0x6E}, // B = B, ACSII 66
{0x7E, 0x81, 0x81, 0x81, 0x42}, // C = C, ACSII 67
{0xFF, 0x81, 0x81, 0x42, 0x3C}, // D = D, ACSII 68
{0xFF, 0x91, 0x91, 0x91, 0x81}, // E = E, ACSII 69
{0xFF, 0x90, 0x90, 0x90, 0x80}, // F = F, ACSII 70
{0x7E, 0x81, 0x89, 0x89, 0x4E}, // G = G, ACSII 71
{0xFF, 0x10, 0x10, 0x10, 0xFF}, // H = H, ACSII 72
{0x81, 0x81, 0xFF, 0x81, 0x81}, // I = I, ACSII 73
{0x06, 0x01, 0x01, 0x01, 0xFE}, // J = J, ACSII 74
{0xFF, 0x18, 0x24, 0x42, 0x81}, // K = K, ACSII 75
{0xFF, 0x01, 0x01, 0x01, 0x01}, // L = L, ACSII 76
{0xFF, 0x40, 0x30, 0x40, 0xFF}, // M = M, ACSII 77
{0xFF, 0x40, 0x30, 0x08, 0xFF}, // N = N, ACSII 78
{0x7E, 0x81, 0x81, 0x81, 0x7E}, // O = O, ACSII 79
{0xFF, 0x88, 0x88, 0x88, 0x70}, // P = P, ACSII 80
{0x7E, 0x81, 0x85, 0x82, 0x7D}, // Q = Q, ACSII 81
{0xFF, 0x88, 0x8C, 0x8A, 0x71}, // R = R, ACSII 82
{0x61, 0x91, 0x91, 0x91, 0x8E}, // S = S, ACSII 83
{0x80, 0x80, 0xFF, 0x80, 0x80}, // T = T, ACSII 84
{0xFE, 0x01, 0x01, 0x01, 0xFE}, // U = U, ACSII 85
{0xF0, 0x0C, 0x03, 0x0C, 0xF0}, // V = V, ACSII 86
{0xFF, 0x02, 0x0C, 0x02, 0xFF}, // W = W, ACSII 87
{0xC3, 0x24, 0x18, 0x24, 0xC3}, // X = X, ACSII 88
{0xE0, 0x10, 0x0F, 0x10, 0xE0}, // Y = Y, ACSII 89
{0x83, 0x85, 0x99, 0xA1, 0xC1}, // Z = Z, ACSII 90
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = [, ACSII 91
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 92
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = ], ACSII 93
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = ^, ACSII 94
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = _, ACSII 95
{0x00, 0xA0, 0xC0, 0x00, 0x00}, // ‘ = `, ACSII 96
{0x06, 0x29, 0x29, 0x29, 0x1F}, // a = a, ACSII 97
{0xFF, 0x09, 0x11, 0x11, 0x0E}, // b = b, ACSII 98
{0x1E, 0x21, 0x21, 0x21, 0x12}, // c = c, ACSII 99
{0x0E, 0x11, 0x11, 0x09, 0xFF}, // d = d, ACSII 100
{0x0E, 0x15, 0x15, 0x15, 0x0C}, // e = e, ACSII 101
{0x08, 0x7F, 0x88, 0x80, 0x40}, // f = f, ACSII 102
{0x30, 0x49, 0x49, 0x49, 0x7E}, // g = g, ACSII 103
{0xFF, 0x08, 0x10, 0x10, 0x0F}, // h = h, ACSII 104
{0x00, 0x00, 0x5F, 0x00, 0x00}, // i = i, ACSII 105
{0x02, 0x01, 0x21, 0xBE, 0x00}, // j = j, ACSII 106
{0xFF, 0x04, 0x0A, 0x11, 0x00}, // k = k, ACSII 107
{0x00, 0x81, 0xFF, 0x01, 0x00}, // l = l, ACSII 108
{0x3F, 0x20, 0x18, 0x20, 0x1F}, // m = m, ACSII 109
{0x3F, 0x10, 0x20, 0x20, 0x1F}, // n = n, ACSII 110
{0x0E, 0x11, 0x11, 0x11, 0x0E}, // o = o, ACSII 111
{0x3F, 0x24, 0x24, 0x24, 0x18}, // p = p, ACSII 112
{0x10, 0x28, 0x28, 0x18, 0x3F}, // q = q, ACSII 113
{0x1F, 0x08, 0x10, 0x10, 0x08}, // r = r, ACSII 114
{0x09, 0x15, 0x15, 0x15, 0x02}, // s = s, ACSII 115
{0x20, 0xFE, 0x21, 0x01, 0x02}, // t = t, ACSII 116
{0x1E, 0x01, 0x01, 0x02, 0x1F}, // u = u, ACSII 117
{0x1C, 0x02, 0x01, 0x02, 0x1C}, // v = v, ACSII 118
{0x1E, 0x01, 0x0E, 0x01, 0x1E}, // w = w, ACSII 119
{0x11, 0x0A, 0x04, 0x0A, 0x11}, // x = x, ACSII 120
{0x00, 0x39, 0x05, 0x05, 0x3E}, // y = y, ACSII 121
{0x11, 0x13, 0x15, 0x19, 0x11}, // z = z, ACSII 122
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = {, ACSII 123
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = |, ACSII 124
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = }, ACSII 125
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = ~, ACSII 126
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Block = , ACSII 127
};// end array
//****setup****setup****setup****setup****setup****setup****setup****setup****setup****setup****setup****setup****setup
void setup(){
SPI.setBitOrder(MSBFIRST);//Most Significant Bit First
SPI.setDataMode(SPI_MODE0);// Mode 0 Rising edge of data, keep clock low
SPI.setClockDivider(SPI_CLOCK_DIV2);//Run the data in at 16MHz/2 - 8MHz
//Serial.begin(115200);// if you need it?
noInterrupts();// kill interrupts until everybody is set up
//We use Timer 1 to refresh the cube
TCCR1A = B00000000;//Register A all 0's since we're not toggling any pins
TCCR1B = B00001011;//bit 3 set to place in CTC mode, will call an interrupt on a counter match
//bits 0 and 1 are set to divide the clock by 64, so 16MHz/64=250kHz
TIMSK1 = B00000010;//bit 1 set to call the interrupt on an OCR1A match
OCR1A=35; // you can play with this, but I set it to 30, which means:
//our clock runs at 250kHz, which is 1/250kHz = 4us
//with OCR1A set to 30, this means the interrupt will be called every (30+1)x4us=124us,
// which gives a multiplex frequency of about 8kHz
// here I just set up the anode array, this is what's written to the anode shift register, to enable each level
anode[0]=B00000001;
anode[1]=B00000010;
anode[2]=B00000100;
anode[3]=B00001000;
anode[4]=B00010000;
anode[5]=B00100000;
anode[6]=B01000000;
anode[7]=B10000000;
// don't hate on how I assigned the values to this register! haha
//finally set up the Outputs
pinMode(latch_pin, OUTPUT);//Latch
pinMode(data_pin, OUTPUT);//MOSI DATA
pinMode(clock_pin, OUTPUT);//SPI Clock
//pinMode(blank_pin, OUTPUT);//Output Enable important to do this last, so LEDs do not flash on boot up
SPI.begin();//start up the SPI library
interrupts();//let the show begin, this lets the multiplexing start
}//***end setup***end setup***end setup***end setup***end setup***end setup***end setup***end setup***end setup***end setup
void loop(){//***start loop***start loop***start loop***start loop***start loop***start loop***start loop***start loop***start loop
//Each animation located in a sub routine
// To control an LED, you simply:
// LED(level you want 0-7, row you want 0-7, column you want 0-7, red brighness 0-15, green brighness 0-15, blue brighness 0-15);
// TEST ANIMATIONS
//test_colours();
//pause();
//skip();
//test();
// ANIMATIONS
//letterFwd("Welcome", 1); //message to show, iterations - Not working properly
message_scroll("Welcome",1); // message to scroll, iterations
upDown (100); // number of drops
clean();
snakes(150); // Iterations
clean();
fireworks (10,35,0); // Iterations, Nuber sparks, delay
square_frame_centre(5); // Iterations
clean();
rainVersionTwo();
clean();
folder();
clean();
sinwaveTwo();
clean();
wipe_out();
clean();
bouncyvTwo();
clean();
color_wheelTWO();
clean();
harlem_shake();
clean();
matrix();
clean();
wave();
clean();
}//***end loop***end loop***end loop***end loop***end loop***end loop***end loop***end loop***end loop***end loop***end loop***end loop
void LED(int level, int row, int column, byte red, byte green, byte blue){ //****LED Routine****LED Routine****LED Routine****LED Routine
//This is where it all starts
//This routine is how LEDs are updated, with the inputs for the LED location and its R G and B brightness levels
// First, check and make sure nothing went beyond the limits, just clamp things at either 0 or 7 for location, and 0 or 15 for brightness
level = constrain (level, 0, 7);
row = constrain (row, 0, 7);
column = constrain (column, 0, 7);
red = constrain (red, 0, 15);
green = constrain (green, 0, 15);
blue = constrain (blue, 0, 15);
//There are 512 LEDs in the cube, so when we write to level 2, column 5, row 4, that needs to be translated into a number from 0 to 511
//This looks confusing, I know...
int whichbyte = int(((level*64)+(row*8)+column)/8);
// The first level LEDs are first in the sequence, then 2nd level, then third, and so on
//the (level*64) is what indexes the level's starting place, so level 0 are LEDs 0-63, level 1 are LEDs 64-127, and so on
//The column counts left to right 0-7 and the row is back to front 0-7
//This means that if you had level 0, row 0, the bottom back row would count from 0-7,
//so if you looked down on the cube, and only looked at the bottom level
// 00 01 02 03 04 05 06 07
// 08 09 10 11 12 13 14 15
// 16 17 18 19 20 21 22 23
// 24 25 26 27 28 29 30 31
// 32 33 34 35 36 37 38 39
// 40 41 42 43 44 45 46 47
// 48 49 50 51 52 53 54 55
// 56 57 58 59 60 61 62 63
//Then, if you incremented the level, the top right of the grid above would start at 64
//The reason for doing this, is so you don't have to memorize a number for each LED, allowing you to use level, row, column
//Now, what about the divide by 8 in there?
//...well, we have 8 bits per byte, and we have 64 bytes in memory for all 512 bits needed for each LED, so
//we divide the number we just found by 8, and take the integ7er of it, so we know which byte, that bit is located
//confused? that's ok, let's take an example, if we wanted to write to the LED to the last LED in the cube, we would write a 7, 7, 7
// giving (7*64)+(7*8)=7 = 511, which is right, but now let's divide it by 8, 511/8 = 63.875, and take the int of it so, we get 63,
//this is the last byte in the array, which is right since this is the last LED
// This next variable is the same thing as before, but here we don't divide by 8, so we get the LED number 0-511
int wholebyte=(level*64)+(row*8)+column;
//This will all make sense in a sec
//This is 4 bit color resolution, so each color contains x4 64 byte arrays, explanation below:
bitWrite(red0[whichbyte], wholebyte-(8*whichbyte), bitRead(red, 0));
bitWrite(red1[whichbyte], wholebyte-(8*whichbyte), bitRead(red, 1));
bitWrite(red2[whichbyte], wholebyte-(8*whichbyte), bitRead(red, 2));
bitWrite(red3[whichbyte], wholebyte-(8*whichbyte), bitRead(red, 3));
bitWrite(green0[whichbyte], wholebyte-(8*whichbyte), bitRead(green, 0));
bitWrite(green1[whichbyte], wholebyte-(8*whichbyte), bitRead(green, 1));
bitWrite(green2[whichbyte], wholebyte-(8*whichbyte), bitRead(green, 2));
bitWrite(green3[whichbyte], wholebyte-(8*whichbyte), bitRead(green, 3));
bitWrite(blue0[whichbyte], wholebyte-(8*whichbyte), bitRead(blue, 0));
bitWrite(blue1[whichbyte], wholebyte-(8*whichbyte), bitRead(blue, 1));
bitWrite(blue2[whichbyte], wholebyte-(8*whichbyte), bitRead(blue, 2));
bitWrite(blue3[whichbyte], wholebyte-(8*whichbyte), bitRead(blue, 3));
//Are you now more confused? You shouldn't be! It's starting to make sense now. Notice how each line is a bitWrite, which is,
//bitWrite(the byte you want to write to, the bit of the byte to write, and the 0 or 1 you want to write)
//This means that the 'whichbyte' is the byte from 0-63 in which the bit corresponding to the LED from 0-511
//Is making sense now why we did that? taking a value from 0-511 and converting it to a value from 0-63, since each LED represents a bit in
//an array of 64 bytes.
//Then next line is which bit 'wholebyte-(8*whichbyte)'
//This is simply taking the LED's value of 0-511 and subracting it from the BYTE its bit was located in times 8
//Think about it, byte 63 will contain LEDs from 504 to 511, so if you took 505-(8*63), you get a 1, meaning that,
//LED number 505 is is located in bit 1 of byte 63 in the array
//is that it? No, you still have to do the bitRead of the brightness 0-15 you are trying to write,
//if you wrote a 15 to RED, all 4 arrays for that LED would have a 1 for that bit, meaning it will be on 100%
//This is why the four arrays read 0-4 of the value entered in for RED, GREEN, and BLUE
//hopefully this all makes some sense?
}//****LED routine end****LED routine end****LED routine end****LED routine end****LED routine end****LED routine end****LED routine end
ISR(TIMER1_COMPA_vect){//***MultiPlex BAM***MultiPlex BAM***MultiPlex BAM***MultiPlex BAM***MultiPlex BAM***MultiPlex BAM***MultiPlex BAM
//This routine is called in the background automatically at frequency set by OCR1A
//In this code, I set OCR1A to 30, so this is called every 124us, giving each level in the cube 124us of ON time
//There are 8 levels, so we have a maximum brightness of 1/8, since the level must turn off before the next level is turned on
//The frequency of the multiplexing is then 124us*8=992us, or 1/992us= about 1kHz
PORTL |= 1<<4;//The first thing we do is turn all of the LEDs OFF, by writing a 1 to the blank pin
//Note, in my bread-boarded version, I was able to move this way down in the cube, meaning that the OFF time was minimized
//do to signal integrity and parasitic capcitance, my rise/fall times, required all of the LEDs to first turn off, before updating
//otherwise you get a ghosting effect on the previous level
//This is 4 bit 'Bit angle Modulation' or BAM, There are 8 levels, so when a '1' is written to the color brightness,
//each level will have a chance to light up for 1 cycle, the BAM bit keeps track of which bit we are modulating out of the 4 bits
//Bam counter is the cycle count, meaning as we light up each level, we increment the BAM_Counter
if(BAM_Counter==8)
BAM_Bit++;
else
if(BAM_Counter==24)
BAM_Bit++;
else
if(BAM_Counter==56)
BAM_Bit++;
BAM_Counter++;//Here is where we increment the BAM counter
switch (BAM_Bit){//The BAM bit will be a value from 0-3, and only shift out the arrays corresponding to that bit, 0-3
//Here's how this works, each case is the bit in the Bit angle modulation from 0-4,
//Next, it depends on which level we're on, so the byte in the array to be written depends on which level, but since each level contains 64 LED,
//we only shift out 8 bytes for each color
case 0:
for(shift_out=level; shift_out<level+8; shift_out++)
SPI.transfer(red0[shift_out]);
for(shift_out=level; shift_out<level+8; shift_out++)
SPI.transfer(green0[shift_out]);
for(shift_out=level; shift_out<level+8; shift_out++)
SPI.transfer(blue0[shift_out]);
break;
case 1:
for(shift_out=level; shift_out<level+8; shift_out++)
SPI.transfer(red1[shift_out]);
for(shift_out=level; shift_out<level+8; shift_out++)
SPI.transfer(green1[shift_out]);
for(shift_out=level; shift_out<level+8; shift_out++)
SPI.transfer(blue1[shift_out]);
break;
case 2:
for(shift_out=level; shift_out<level+8; shift_out++)
SPI.transfer(red2[shift_out]);
for(shift_out=level; shift_out<level+8; shift_out++)
SPI.transfer(green2[shift_out]);
for(shift_out=level; shift_out<level+8; shift_out++)
SPI.transfer(blue2[shift_out]);
break;
case 3:
for(shift_out=level; shift_out<level+8; shift_out++)
SPI.transfer(red3[shift_out]);
for(shift_out=level; shift_out<level+8; shift_out++)
SPI.transfer(green3[shift_out]);
for(shift_out=level; shift_out<level+8; shift_out++)
SPI.transfer(blue3[shift_out]);
//Here is where the BAM_Counter is reset back to 0, it's only 4 bit, but since each cycle takes 8 counts,
//, it goes 0 8 16 32, and when BAM_counter hits 64 we reset the BAM
if(BAM_Counter==120){
BAM_Counter=0;
BAM_Bit=0;
}
break;
}//switch_case
SPI.transfer(anode[anodelevel]);//finally, send out the anode level byte
PORTL |= 1<<5;//Latch pin HIGH
PORTL &= ~(1<<5);//Latch pin LOW
PORTL &= ~(1<<4);//Blank pin LOW to turn on the LEDs with the new data
anodelevel++;//inrement the anode level
level = level+8;//increment the level variable by 8, which is used to shift out data, since the next level woudl be the next 8 bytes in the arrays
if(anodelevel==8)//go back to 0 if max is reached
anodelevel=0;
if(level==64)//if you hit 64 on level, this means you just sent out all 63 bytes, so go back
level=0;
pinMode(blank_pin, OUTPUT);//moved down here so outputs are all off until the first call of this function
}//***MultiPlex BAM END***MultiPlex BAM END***MultiPlex BAM END***MultiPlex BAM END***MultiPlex BAM END***MultiPlex BAM END***MultiPlex BAM END
//*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE
//*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE
//*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE
//*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE*+*+*+*+*+*+*+*+*+*+*+*+PUT ANIMATIONS DOWN HERE
void test(){
for (int i=0;i<8;i++){
int OnOff = 1;
LED (i,7,0, OnOff * 15, OnOff * 15, OnOff * 15);
}
} // end test
void upDown (unsigned int iterations){
unsigned int fillArray[64];
unsigned int gArray[8] = {15, 13, 11, 9, 7, 5, 3, 0};
unsigned int bArray[8] = {0, 3, 5, 7, 9, 11, 13, 15};
for (int i=0;i<64;i++){
int x = random(2);
if (x==1){
fillArray[i] = 7;}
else {
fillArray[i] = 0;}
} // end i
for (int j=0;j<64;j++){ // randon fill top and bottom layer
int r = j / 8;
int c = j - (r * 8);
LED (fillArray[j] ,r , c , 0, gArray[fillArray[j]], bArray[fillArray[j]]);
} // end j
for (int reps=0;reps<iterations;reps++){
int x = random(64);
int r = x / 8;
int c = x - (r * 8);
if (fillArray[x] == 0){
for (int k=1;k<8;k++){
LED (k-1, r , c , 0,0,0);
LED (k, r , c , 0, gArray[k], bArray[k]);
delay (25);
}
}
else {
for (int k=6;k>=0;k--){
LED (k+1, r , c , 0,0,0);
LED (k, r , c , 0, gArray[k], bArray[k]);
delay (25);
}
} // end else
} // end reps
clean();
} // end upDown
void letterFwd(String messageFwd, int iterations){
int rCol = 15;
int gCol = 15;
int bCol = 15;
unsigned int messageLenFwd = messageFwd.length(); //define lengh of original message
unsigned int delayTime = 50; // delay time between scrolls
char original_Message_Array_Fwd[messageLenFwd]; // set up original_message_Array
messageFwd.toCharArray(original_Message_Array_Fwd,messageLenFwd+1); // seperate original message into individual char's
byte charDisplay[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} ;
for (int i=0; i<iterations; i++){
for (int x=0; x<messageLenFwd; x++){ // repeat for each letter
Serial.println(x,DEC);
for (int c=0;c<5;c++){
int cx = map(c,0,4,4,0);
charDisplay[(cx+1)] = array_ASCII[original_Message_Array_Fwd[x]][c]; // c+1 = offset of 8x5 char in 8x8 grid
} // end c
Serial.println("Map c");
for (int showRow=0; showRow<8; showRow++){ // repeat for each row
//Serial.print("Map r ");
//Serial.println(showRow, DEC);
for (int j=0;j<8;j++){ // repeat for each byte
for (int k=0;k<8;k++){ // repeat for each bit/layer
int OnOffbit = bitRead (charDisplay[j],k);
LED (k,showRow, j, rCol*OnOffbit, gCol*OnOffbit, bCol*OnOffbit);
} // end k
} // end j
delay(delayTime);
for (int j=0;j<8;j++){ // repeat for each byte in next row before clearing previous row - to avoid flicker
for (int k=0;k<8;k++){ // repeat for each bit/layer
int OnOffbit = bitRead (charDisplay[j],k);
LED (k,showRow+1, j, rCol*OnOffbit, gCol*OnOffbit, bCol*OnOffbit);
} // end k
} // end j
for (int j=0;j<8;j++){ // repeat for each byte to clear oringinal row
for (int k=0;k<8;k++){ // repeat for each bit/layer
LED (k,showRow, j, 0,0,0);
} // end k
} // end j
} // end r
}// end x
} // end iterations
} // end letterFwd
void message_scroll(String message,int iterations){
unsigned int messageLen = message.length(); //define lengh of original message
unsigned int delayTime = 40; // delay time between scrolls
char original_Message_Array[messageLen]; // set up original_message_Array
message.toCharArray(original_Message_Array,messageLen+1); // seperate original message into individual char's
int scrollArrayByteLen = (messageLen*5)+(messageLen*2)+13;;// 5 bytes for each character plus 2 buyes betwwen characters for spaces between letters
byte messageScrollArrayByte[scrollArrayByteLen]; // The whole message in bytes will be stored here
unsigned int ScrollArrayByteNumber = 0; // start at first byte
for (int i=0;i<messageLen;i++){ // repeat for each letter
for (int j=0;j<5;j++){ // repeat for 5 bytes in each letter
messageScrollArrayByte[ScrollArrayByteNumber] = array_ASCII[original_Message_Array[i]][j];
ScrollArrayByteNumber++;
}// end j
for (int k=0;k<2;k++){ // repeat twice for two blank spaces
messageScrollArrayByte[ScrollArrayByteNumber] = 0x00; // set byte to zero = ie blank space for next two columns
ScrollArrayByteNumber++;
}// end k
}//end i
for (int k=0;k<13;k++){ // repeat twice for two blank spaces
messageScrollArrayByte[ScrollArrayByteNumber] = 0x00; // set byte to zero = ie blank space for next two columns
ScrollArrayByteNumber++;
}// end k
for ( int repeat_times =0;repeat_times<iterations;repeat_times++){ // Repeat for given number of iterations
for ( int allBytes=0;allBytes<scrollArrayByteLen;allBytes++){
for (int fwd_scroll=13;fwd_scroll>=0;fwd_scroll--){ // move all bytes forward by one
messageDrawScrollArray[fwd_scroll+1] = messageDrawScrollArray[fwd_scroll];
} // end fwd_scroll
messageDrawScrollArray[0] = messageScrollArrayByte[allBytes]; // write bytes into first byte in scroll array one at a time
message_draw_Array(); // draw all 14 bytes
delay(delayTime);
} // end j
} // end repeat_Times Iterations
} // end message Scroll
void message_draw_Array(){
int rCol = 15;
int gCol = 15;
int bCol = 15;
// Convert each byte in drawScrollArray[] into the individual columns
for (int h=0;h<8;h++){
for (int i=0;i<8;i++){
int OnOffbit = bitRead (messageDrawScrollArray[h],i);
LED (i,7,h, rCol*OnOffbit, gCol*OnOffbit, bCol*OnOffbit);
} // end i
} // end h
for (int i=0;i<8;i++){
int OnOffbit = bitRead (messageDrawScrollArray[8],i);
LED (i,6,7, rCol*OnOffbit, gCol*OnOffbit, bCol*OnOffbit);
} // end i
for (int i=0;i<8;i++){
int OnOffbit = bitRead (messageDrawScrollArray[9],i);
LED (i,5,7, rCol*OnOffbit, gCol*OnOffbit, bCol*OnOffbit);
} // end i
for (int i=0;i<8;i++){
int OnOffbit = bitRead (messageDrawScrollArray[10],i);
LED (i,4,7, rCol*OnOffbit, gCol*OnOffbit, bCol*OnOffbit);
} // end i
for (int i=0;i<8;i++){
int OnOffbit = bitRead (messageDrawScrollArray[11],i);
LED (i,3,7, rCol*OnOffbit, gCol*OnOffbit, bCol*OnOffbit);
} // end i
for (int i=0;i<8;i++){
int OnOffbit = bitRead (messageDrawScrollArray[12],i);
LED (i,2,7, rCol*OnOffbit, gCol*OnOffbit, bCol*OnOffbit);
} // end i
for (int i=0;i<8;i++){
int OnOffbit = bitRead (messageDrawScrollArray[13],i);
LED (i,1,7, rCol*OnOffbit, gCol*OnOffbit, bCol*OnOffbit);
} // end i
for (int i=0;i<8;i++){
int OnOffbit = bitRead (messageDrawScrollArray[14],i);
LED (i,0,7, rCol*OnOffbit, gCol*OnOffbit, bCol*OnOffbit);
} // end i
} // end message_draw_Array
void snakes(int iterations){
int delayTime = 60; // change this variable to slow down or speed up animation
int a = random(1,3);
int b = random(1,3);
int c = random(3,5);
int d = random(3,5);
int e = random(5,7);
int f = random(5,7);
for (int i=0;i<iterations;i++){
for(int x=0;x<8;x++){ //Clear level 7
for(int y=0;y<8;y++){
LED(7,x,y,0,0,0);
}}
a = a + map(random (3),0,2,-1,1);
c = c + map(random (3),0,2,-1,1);
e = e + map(random (3),0,2,-1,1);
a = constrain (a,0,5);
c = constrain (c,0,5);
e = constrain (e,0,5);
draw_snake(i,iterations,a,b,c,d,e,f);
shift_all_layers(-1); // shift all levels down 1
delay(delayTime);
b = b + map(random (3),0,2,-1,1);
d = d + map(random (3),0,2,-1,1);
f = f + map(random (3),0,2,-1,1);
b = constrain (b,0,5);
d = constrain (d,0,5);
f = constrain (f,0,5);
draw_snake(i,iterations,a,b,c,d,e,f);
shift_all_layers(-1); // shift all levels down 1
delay(delayTime);
}}// End Snake
void draw_snake(int ii,int iiterations,int aa, int bb, int cc, int dd, int ee, int ff){;
LED(7,aa,bb,0,15,0);
LED(7,aa+1,bb,0,15,0);
LED(7,aa+1,bb+1,0,15,0);
LED(7,aa,bb+1,0,15,0);
if (ii>iiterations/3){
LED(7,cc,dd,0,0,15);
LED(7,cc+1,dd,0,0,15);
LED(7,cc+1,dd+1,0,0,15);
LED(7,cc,dd+1,0,0,15);
}
if (ii>iiterations/3*2){
LED(7,ee,ff,15,0,0);
LED(7,ee+1,ff,15,0,0);
LED(7,ee+1,ff+1,15,0,0);
LED(7,ee,ff+1,15,0,0);
}}// end draw_snake
void fireworks (int iterations, int n, int delayx){
clean();
int i,f,e,x;
float origin_x = 3;
float origin_y = 3;
float origin_z = 3;
int rand_y, rand_x, rand_z;
float slowrate, gravity;
// Particles and their position, x,y,z and their movement, dx, dy, dz
float particles[n][6];
float lastpart[n][3];
for (i=0; i<iterations; i++){ // Main loop here for i iterations
origin_x = rand()%4;
origin_y = rand()%4;
origin_z = rand()%2;
origin_z +=5;
origin_x +=2;
origin_y +=2;
// shoot a particle up in the air
for (e=0;e<origin_z;e++){
LED (e,origin_x,origin_y,15,15,15);
x=(50*e);
delay(30);
clean();
}
// Fill particle array
for (f=0; f<n; f++){
// Position
particles[f][0] = origin_x;
particles[f][1] = origin_y;
particles[f][2] = origin_z;
rand_x = rand()%200;
rand_y = rand()%200;
rand_z = rand()%200;
// Movement
particles[f][3] = 1-(float)rand_x/100; // dx
particles[f][4] = 1-(float)rand_y/100; // dy
particles[f][5] = 1-(float)rand_z/100; // dz
}
// explode
for (e=0; e<25; e++){
slowrate = 1+tan((e+0.1)/20)*10;
gravity = tan((e+0.1)/20)/2;
for (f=0; f<n; f++){
particles[f][0] += particles[f][3]/slowrate;
particles[f][1] += particles[f][4]/slowrate;
particles[f][2] += particles[f][5]/slowrate;
particles[f][2] -= gravity;
if (particles[f][2] <-1){
LED (particles[f][2],particles[f][0],particles[f][1],0,0,0);
}
else {
LED (particles[f][2],particles[f][0],particles[f][1],(random(16)),(random(16)),(random(16)));
}
lastpart[f][2]=particles[f][2];
lastpart[f][0]=particles[f][0];
lastpart[f][1]=particles[f][1];
}
delay(40);
for (f=0; f<n; f++){
LED (lastpart[f][2],lastpart[f][0],lastpart[f][1],0,0,0);
}
}
}} // End Fireworks
void square_frame_centre(int iterations){
int x;
for (int r=0;r<iterations;r++){ // Repeat Loop here
int a=0;
int b=7;
for (x=a;x<=b;x++){ // Draw Outside Frame
draw_frame(x, a, b);
}
delay(100);
for (x=a;x<=b;x++){
clean_frame(x, a, b);
}
a++;
b--;
for (int i=0;i<3;i++){ // Draw shrinking frame
for (x=a;x<=b;x++){
draw_frame(x, a, b);
}// end x loop
delay(30);
for (x=a;x<=b;x++){
clean_frame(x, a, b);
}
a++;
b--;
}// end i loop
a--;
b++;
for (x=a;x<=b;x++){
draw_frame(x, a, b);
}// end x loop
delay(100);
for (x=a;x<=b;x++){
clean_frame(x, a, b);
}
a=a-1;
b=b+1;
for (int i=0;i<2;i++){ // Draw Growing Frame
for (x=a;x<=b;x++){
draw_frame(x, a, b);
}// end x loop
delay(30);
for (x=a;x<=b;x++){
clean_frame(x, a, b);
}
a--;
b++;
}// end i loop
for (x=a;x<=b;x++){ // Draw Outside Frame
draw_frame(x, a, b);
}
delay(100);
}// end r repeat loop
} //End square_frame_centre
void draw_frame(int xx, int aa, int bb){
LED(xx,aa,aa,random(16),random(16),random(16));
LED(aa,xx,aa,random(16),random(16),random(16));
LED(aa,aa,xx,random(16),random(16),random(16));
LED(xx,bb,bb,random(16),random(16),random(16));
LED(bb,xx,bb,random(16),random(16),random(16));
LED(bb,bb,xx,random(16),random(16),random(16));
LED(xx,aa,bb,random(16),random(16),random(16));
LED(aa,xx,bb,random(16),random(16),random(16));
LED(aa,bb,xx,random(16),random(16),random(16));
LED(xx,bb,aa,random(16),random(16),random(16));
LED(bb,xx,aa,random(16),random(16),random(16));
LED(bb,aa,xx,random(16),random(16),random(16));
}// End draw_frame
void clean_frame(int xxx, int aaa, int bbb){
LED(xxx,aaa,aaa,0,0,0);
LED(aaa,xxx,aaa,0,0,0);
LED(aaa,aaa,xxx,0,0,0);
LED(xxx,bbb,bbb,0,0,0);
LED(bbb,xxx,bbb,0,0,0);
LED(bbb,bbb,xxx,0,0,0);
LED(xxx,aaa,bbb,0,0,0);
LED(aaa,xxx,bbb,0,0,0);
LED(aaa,bbb,xxx,0,0,0);
LED(xxx,bbb,aaa,0,0,0);
LED(bbb,xxx,aaa,0,0,0);
LED(bbb,aaa,xxx,0,0,0);
}// End draw_frame
void pause(){
for (int x=1;x<7;x++){
LED(x,7,6,15,0,0);
LED(x,7,5,15,0,0);
LED(x,7,2,15,0,0);
LED(x,7,1,15,0,0);
}
} // End Pause
void skip(){
LED(1,7,5,0,15,0);
LED(1,7,4,0,15,0);
LED(2,7,4,0,15,0);
LED(2,7,3,0,15,0);
LED(3,7,3,0,15,0);
LED(3,7,2,0,15,0);
LED(4,7,3,0,15,0);
LED(4,7,2,0,15,0);
LED(5,7,3,0,15,0);
LED(5,7,4,0,15,0);
LED(6,7,4,0,15,0);
LED(6,7,5,0,15,0);
} //End Skip
void test_colours(){
for (int x=0;x<8;x++){
for (int y=0;y<8;y++){
for (int z=0;z<8;z++){
LED (x,y,z,15,0,0);
}
}
}
delay (50);
for (int x=0;x<8;x++){
for (int y=0;y<8;y++){
for (int z=0;z<8;z++){
LED (x,y,z,0,15,0);
}
}
}
delay (50);
for (int x=0;x<8;x++){
for (int y=0;y<8;y++){
for (int z=0;z<8;z++){
LED (x,y,z,0,0,15);
}
}
}
delay (50);
for (int x=0;x<8;x++){
for (int y=0;y<8;y++){
for (int z=0;z<8;z++){
LED (x,y,z,15,15,15);
}
}
}
delay (50);
} // End test_colours
void shift_all_layers(int layerShift){
int startLayer = 0;
if (layerShift == 1){
startLayer = 6;
}
if (layerShift == -1){
startLayer = 1;
}
for (int x=0;x<7;x++){ //repeat copy row 7 time
for (int y=0;y<8;y++){
int arrayTo = (startLayer * 8) + y + (8 * layerShift);
int arrayFrom = (startLayer * 8) + y;
red0[arrayTo] = red0[arrayFrom];
red1[arrayTo] = red1[arrayFrom];
red2[arrayTo] = red2[arrayFrom];
red3[arrayTo] = red3[arrayFrom];
green0[arrayTo] = green0[arrayFrom];
green1[arrayTo] = green1[arrayFrom];
green2[arrayTo] = green2[arrayFrom];
green3[arrayTo] = green3[arrayFrom];
blue0[arrayTo] = blue0[arrayFrom];
blue1[arrayTo] = blue1[arrayFrom];
blue2[arrayTo] = blue2[arrayFrom];
blue3[arrayTo] = blue3[arrayFrom];
}
startLayer = startLayer - layerShift;
}
}// end shift_all_layers
void matrix(){ // ****Matrix****Matrix****Matrix****Matrix****Matrix****Matrix****Matrix****Matrix**
start=millis();
while(millis()-start<15000){
int delayTime = 25;
for(int x=0;x<8;x++){ //Clear level 7
for(int y=0;y<8;y++){
LED(7,x,y,0,0,0);
}}
for(int x=0;x<60;x++){ //Play with the variable here
int i = random(8);
int j = random(8);
//int r = random(16);
int g = random(16);
//int b = random(16);
LED(7,i,j,0,g,0);
}
delay(delayTime);
int k = random(1,5); //Play with this value
for (int x=0;x<k;x++){
shift_all_layers(-1); // shift all levels down 1
delay(delayTime);
}
}
} // End Matrix
void wipe_out(){//*****wipe_out*****wipe_out*****wipe_out*****wipe_out*****wipe_out*****wipe_out*****wipe_out*****wipe_out
int xxx=0, yyy=0, zzz=0;
int fx=random(8), fy=random(8), fz=random(8), direct, fxm=1, fym=1, fzm=1, fxo=0, fyo=0, fzo=0;
int ftx=random(8), fty=random(8), ftz=random(8), ftxm=1, ftym=1, ftzm=1, ftxo=0, ftyo=0, ftzo=0;
int select, rr, gg, bb, rrt, ggt, bbt;
for(xxx=0; xxx<8; xxx++){
for(yyy=0; yyy<8; yyy++){
for(zzz=0; zzz<8; zzz++){
LED(xxx, yyy, zzz, 0, 0, 0);
}}}
select=random(3);
if(select==0){
rr=random(1, 16);
gg=random(1, 16);
bb=0;}
if(select==1){
rr=random(1, 16);
gg=0;
bb=random(1, 16);}
if(select==2){
rr=0;
gg=random(1, 16);
bb=random(1, 16);}
select=random(3);
if(select==0){
rrt=random(1, 16);
ggt=random(1, 16);
bbt=0;}
if(select==1){
rrt=random(1, 16);
ggt=0;
bbt=random(1, 16);}
if(select==2){
rrt=0;
ggt=random(1, 16);
bbt=random(1, 16);}
start=millis();
while(millis()-start<10000){
//fx=random(8); fy=random(8); fz=random(8);
LED(fxo, fyo, fzo, 0, 0, 0);
LED(fxo, fyo, fzo+1, 0, 0, 0);
LED(fxo, fyo, fzo-1, 0, 0, 0);
LED(fxo+1, fyo, fzo, 0, 0, 0);
LED(fxo-1, fyo, fzo, 0, 0, 0);
LED(fxo, fyo+1, fzo, 0, 0, 0);
LED(fxo, fyo-1, fzo, 0, 0, 0);
LED(ftxo, ftyo, ftzo, 0, 0, 0);
LED(ftxo, ftyo, ftzo+1, 0, 0, 0);
LED(ftxo, ftyo, ftzo-1, 0, 0, 0);
LED(ftxo+1, ftyo, ftzo, 0, 0, 0);
LED(ftxo-1, ftyo, ftzo, 0, 0, 0);
LED(ftxo, ftyo+1, ftzo, 0, 0, 0);
LED(ftxo, ftyo-1, ftzo, 0, 0, 0);
LED(ftx, fty, ftz, rr, gg, bb);
LED(ftx, fty, ftz+1, rr, gg, bb);
LED(ftx, fty, ftz-1, rr, gg, bb);
LED(ftx+1, fty, ftz, rr, gg, bb);
LED(ftx-1, fty, ftz, rr, gg, bb);
LED(ftx, fty+1, ftz, rr, gg, bb);
LED(ftx, fty-1, ftz, rr, gg, bb);
LED(fx, fy, fz, rrt, ggt, bbt);
LED(fx, fy, fz+1, rrt, ggt, bbt);
LED(fx, fy, fz-1, rrt, ggt, bbt);
LED(fx+1, fy, fz, rrt, ggt, bbt);
LED(fx-1, fy, fz, rrt, ggt, bbt);
LED(fx, fy+1, fz, rrt, ggt, bbt);
LED(fx, fy-1, fz, rrt, ggt, bbt);
delay(10);
fxo=fx;
fyo=fy;
fzo=fz;
ftxo=ftx;
ftyo=fty;
ftzo=ftz;
direct=random(3);
if(direct==0)
fx= fx+fxm;
if(direct==1)
fy= fy+fym;
if(direct==2)
fz= fz+fzm;
if(fx<0){
fx=0; fxm=1;}
if(fx>7){
fx=7; fxm=-1;}
if(fy<0){
fy=0; fym=1;}
if(fy>7){
fy=7; fym=-1;}
if(fz<0){
fz=0; fzm=1;}
if(fz>7){
fz=7; fzm=-1;}
direct=random(3);
if(direct==0)
ftx= ftx+ftxm;
if(direct==1)
fty= fty+ftym;
if(direct==2)
ftz= ftz+ftzm;
if(ftx<0){
ftx=0; ftxm=1;}
if(ftx>7){
ftx=7; ftxm=-1;}
if(fty<0){
fty=0; ftym=1;}
if(fty>7){
fty=7; ftym=-1;}
if(ftz<0){
ftz=0; ftzm=1;}
if(ftz>7){
ftz=7; ftzm=-1;}
}//while
for(xxx=0; xxx<8; xxx++){
for(yyy=0; yyy<8; yyy++){
for(zzz=0; zzz<8; zzz++){
LED(xxx, yyy, zzz, 0, 0, 0);
}}}
}//wipeout
void rainVersionTwo(){//****rainVersionTwo****rainVersionTwo****rainVersionTwo****rainVersionTwo****rainVersionTwo
int x[64], y[64], z[64], addr, leds=64, bright=1, ledcolor, colowheel;
int xx[64], yy[64], zz[64], xold[64], yold[64], zold[64], slowdown;
for(addr=0; addr<64; addr++){
x[addr]=random(8);
y[addr]=random(8);
z[addr]=random(8);
xx[addr]=random(16);
yy[addr]=random(16);
zz[addr]=random(16);
}
start=millis();
while(millis()-start<20000){
//wipe_out();
//for(addr=0; addr<leds; addr++)
//LED(zold[addr], xold[addr], yold[addr], 0, 0, 0);
if(ledcolor<200){
for(addr=0; addr<leds; addr++){
LED(zold[addr], xold[addr], yold[addr], 0, 0, 0);
if(z[addr]>=7)
LED(z[addr], x[addr], y[addr], 0, 5, 15);
if(z[addr]==6)
LED(z[addr], x[addr], y[addr], 0, 1, 9);
if(z[addr]==5)
LED(z[addr], x[addr], y[addr], 0, 0, 10);
if(z[addr]==4)
LED(z[addr], x[addr], y[addr], 1, 0, 11);
if(z[addr]==3)
LED(z[addr], x[addr], y[addr], 3, 0, 12);
if(z[addr]==2)
LED(z[addr], x[addr], y[addr], 10, 0, 15);
if(z[addr]==1)
LED(z[addr], x[addr], y[addr], 10, 0, 10);
if(z[addr]<=0)
LED(z[addr], x[addr], y[addr], 10, 0, 1);
}}//200
if(ledcolor>=200&&ledcolor<300){
for(addr=0; addr<leds; addr++){
LED(zold[addr], xold[addr], yold[addr], 0, 0, 0);
if(z[addr]>=7)
LED(z[addr], x[addr], y[addr], 15, 15, 0);
if(z[addr]==6)
LED(z[addr], x[addr], y[addr], 10, 10, 0);
if(z[addr]==5)
LED(z[addr], x[addr], y[addr], 15, 5, 0);
if(z[addr]==4)
LED(z[addr], x[addr], y[addr], 15, 2, 0);
if(z[addr]==3)
LED(z[addr], x[addr], y[addr], 15, 1, 0);
if(z[addr]==2)
LED(z[addr], x[addr], y[addr], 15, 0, 0);
if(z[addr]==1)
LED(z[addr], x[addr], y[addr], 12, 0, 0);
if(z[addr]<=0)
LED(z[addr], x[addr], y[addr], 10, 0, 0);
}}//300
if(ledcolor>=300&&ledcolor<400){
}
if(ledcolor>=500&&ledcolor<600){
}
ledcolor++;
if(ledcolor>=300)
ledcolor=0;
for(addr=0; addr<leds; addr++){
xold[addr]=x[addr];
yold[addr]=y[addr];
zold[addr]=z[addr];
}
delay(15);
//for(addr=0; addr<leds; addr++)
//LED(z[addr], x[addr], y[addr], 0, 0, 0);
for(addr=0; addr<leds; addr++){
//slowdown = random(2);
//if(bitRead(z[addr],0))
z[addr] = z[addr]-1;
// x[addr] = x[addr]+1;
// y[addr] = y[addr]+1;
if(z[addr]<random(-100,0)){
x[addr]=random(8);
y[addr]=random(8);
int select=random(3);
if(select==0){
xx[addr]=0;
zz[addr]=random(16);
yy[addr]=random(16);
//zz[addr]=0;
}
if(select==1){
xx[addr]=random(16);
zz[addr]=0;
yy[addr]=random(16);
//yy[addr]=0;
}
if(select==2){
xx[addr]=random(16);
zz[addr]=random(16);
yy[addr]=0;
}
z[addr]=7;
}//-check
}//add
}//while
}//rainv2
void folder(){//****folder****folder****folder****folder****folder****folder****folder****folder****folder
int xx, yy, zz, pullback[16], state=0, backorfront=7;//backorfront 7 for back 0 for front
int folderaddr[16], LED_Old[16], oldpullback[16], ranx=random(16), rany=random(16), ranz=random(16), ranselect;
int bot=0, top=1, right=0, left=0, back=0, front=0, side=0, side_select;
folderaddr[0]=-7;
folderaddr[1]=-6;
folderaddr[2]=-5;
folderaddr[3]=-4;
folderaddr[4]=-3;
folderaddr[5]=-2;
folderaddr[6]=-1;
folderaddr[7]=0;
for(xx=0; xx<8; xx++){
oldpullback[xx]=0;
pullback[xx]=0;
}
start=millis();
while(millis()-start<10000){
if(top==1){
if(side==0){
//top to left-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(7-LED_Old[yy], yy-oldpullback[yy],xx , 0, 0, 0);
LED(7-folderaddr[yy], yy-pullback[yy],xx , ranx, rany, ranz);
}}}
if(side==2){
//top to back-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(7-LED_Old[yy], xx, yy-oldpullback[yy], 0, 0, 0);
LED(7-folderaddr[yy], xx, yy-pullback[yy], ranx, rany, ranz);
}}}
if(side==3){
//top-side to front-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(7-LED_Old[7-yy], xx, yy+oldpullback[yy], 0, 0, 0);
LED(7-folderaddr[7-yy], xx, yy+pullback[yy], ranx, rany, ranz);
}}}
if(side==1){
//top-side to right
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(7-LED_Old[7-yy], yy+oldpullback[yy],xx , 0, 0, 0);
LED(7-folderaddr[7-yy], yy+pullback[yy],xx , ranx, rany, ranz);
}}}
}//top
if(right==1){
if(side==4){
//right-side to top
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(yy+oldpullback[7-yy],7-LED_Old[7-yy],xx , 0, 0, 0);
LED( yy+pullback[7-yy],7-folderaddr[7-yy],xx , ranx, rany, ranz);
}}}
if(side==3){
//right-side to front-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(xx, 7-LED_Old[7-yy],yy+oldpullback[yy], 0, 0, 0);
LED(xx,7-folderaddr[7-yy], yy+pullback[yy], ranx, rany, ranz);
}}}
if(side==2){
//right-side to back-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(xx, 7-LED_Old[yy],yy-oldpullback[yy], 0, 0, 0);
LED(xx,7-folderaddr[yy], yy-pullback[yy], ranx, rany, ranz);
}}}
if(side==5){
//right-side to bottom
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(yy-oldpullback[yy],7-LED_Old[yy],xx , 0, 0, 0);
LED( yy-pullback[yy],7-folderaddr[yy],xx , ranx, rany, ranz);
}}}
}//right
if(left==1){
if(side==4){
//left-side to top
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(yy+oldpullback[yy],LED_Old[7-yy],xx , 0, 0, 0);
LED( yy+pullback[yy],folderaddr[7-yy],xx , ranx, rany, ranz);
}}}
if(side==3){
//left-side to front-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(xx, LED_Old[7-yy],yy+oldpullback[yy], 0, 0, 0);
LED(xx,folderaddr[7-yy], yy+pullback[yy], ranx, rany, ranz);
}}}
if(side==2){
//left-side to back-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(xx, LED_Old[yy],yy-oldpullback[yy], 0, 0, 0);
LED(xx,folderaddr[yy], yy-pullback[yy], ranx, rany, ranz);
}}}
if(side==5){
//left-side to bottom
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(yy-oldpullback[yy],LED_Old[yy],xx , 0, 0, 0);
LED( yy-pullback[yy],folderaddr[yy],xx , ranx, rany, ranz);
}}}
}//left
if(back==1){
if(side==1){
//back-side to right-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(xx, yy+oldpullback[yy],LED_Old[7-yy], 0, 0, 0);
LED(xx, yy+pullback[yy],folderaddr[7-yy], ranx, rany, ranz);
}}}
if(side==4){
// back-side to top-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(yy+oldpullback[yy],xx,LED_Old[7-yy] , 0, 0, 0);
LED( yy+pullback[yy],xx,folderaddr[7-yy] , ranx, rany, ranz);
}}}
if(side==5){
// back-side to bottom
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(yy-oldpullback[yy],xx,LED_Old[yy] , 0, 0, 0);
LED( yy-pullback[yy],xx,folderaddr[yy] , ranx, rany, ranz);
}}}//state1
if(side==0){
//back-side to left-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(xx, yy-oldpullback[yy],LED_Old[yy], 0, 0, 0);
LED(xx, yy-pullback[yy],folderaddr[yy], ranx, rany, ranz);
}}}
}//back
if(bot==1){
if(side==1){
// bottom-side to right-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(LED_Old[7-yy], yy+oldpullback[yy],xx , 0, 0, 0);
LED(folderaddr[7-yy], yy+pullback[yy],xx , ranx, rany, ranz);
}}}
if(side==3){
//bottom to front-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(LED_Old[7-yy], xx, yy+oldpullback[yy], 0, 0, 0);
LED(folderaddr[7-yy], xx, yy+pullback[yy], ranx, rany, ranz);
}}}
if(side==2){
//bottom to back-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(LED_Old[yy], xx, yy-oldpullback[yy], 0, 0, 0);
LED(folderaddr[yy], xx, yy-pullback[yy], ranx, rany, ranz);
}}}
if(side==0){
//bottom to left-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(LED_Old[yy], yy-oldpullback[yy],xx , 0, 0, 0);
LED(folderaddr[yy], yy-pullback[yy],xx , ranx, rany, ranz);
}}}
}//bot
if(front==1){
if(side==0){
//front-side to left-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(xx, yy-oldpullback[yy],7-LED_Old[yy], 0, 0, 0);
LED(xx, yy-pullback[yy],7-folderaddr[yy], ranx, rany, ranz);
}}}
if(side==5){
// front-side to bottom
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(yy-oldpullback[yy],xx,7-LED_Old[yy] , 0, 0, 0);
LED( yy-pullback[yy],xx,7-folderaddr[yy] , ranx, rany, ranz);
}}}
if(side==4){
// front-side to top-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(yy+oldpullback[yy],xx,7-LED_Old[7-yy] , 0, 0, 0);
LED( yy+pullback[yy],xx,7-folderaddr[7-yy] , ranx, rany, ranz);
}}}
if(side==1){
//front-side to right-side
for(yy=0; yy<8; yy++){
for(xx=0; xx<8; xx++){
LED(xx, yy+oldpullback[yy],7-LED_Old[7-yy], 0, 0, 0);
LED(xx, yy+pullback[yy],7-folderaddr[7-yy], ranx, rany, ranz);
}}}
}//front
delay(5);// DELAY DELAY DELAY
for(xx=0; xx<8; xx++){
LED_Old[xx]=folderaddr[xx];
oldpullback[xx]=pullback[xx];
}
if(folderaddr[7]==7){
// pullback=8;
for(zz=0; zz<8; zz++)
pullback[zz] = pullback[zz]+1;
if(pullback[7]==8){//finished with fold
delay(10);
//state++;
//if(state==4)
//state=0;
ranselect= random(3);
if(ranselect==0){
ranx=0;
rany=random(1,16);
ranz=random(1,16);}
if(ranselect==1){
ranx=random(1,16);
rany=0;
ranz=random(1,16);}
if(ranselect==2){
ranx=random(1,16);
rany=random(1,16);
ranz=0;}
side_select=random(3);
if(top==1){// TOP
top=0;
if(side==0){//top to left
left=1;
if(side_select==0) side=2;
if(side_select==1) side=3;
//if(side_select==2) side=4;
if(side_select==2) side=5;} else
if(side==1){//top to right
right=1;
if(side_select==0) side=5;
if(side_select==1) side=2;
if(side_select==2) side=3;
//if(side_select==3) side=4;
} else
if(side==2){//top to back
back=1;
if(side_select==0) side=0;
if(side_select==1) side=1;
if(side_select==2) side=5;
//if(side_select==3) side=4;
} else
if(side==3){//top to front
front=1;
if(side_select==0) side=0;
if(side_select==1) side=1;
if(side_select==2) side=5;
//if(side_select==3) side=4;
}
} else//top
if(bot==1){// BOTTOM
bot=0;
if(side==0){//bot to left
left=1;
if(side_select==0) side=2;
if(side_select==1) side=3;
if(side_select==2) side=4;
//if(side_select==3) side=5;
} else
if(side==1){//bot to right
right=1;
//if(side_select==0) side=5;
if(side_select==0) side=2;
if(side_select==1) side=3;
if(side_select==2) side=4;} else
if(side==2){//bot to back
back=1;
if(side_select==0) side=0;
if(side_select==1) side=1;
//if(side_select==2) side=5;
if(side_select==2) side=4;} else
if(side==3){//bot to front
front=1;
if(side_select==0) side=0;
if(side_select==1) side=1;
//if(side_select==2) side=5;
if(side_select==2) side=4;}
} else//bot
if(right==1){// RIGHT
right=0;
if(side==4){//right to top
top=1;
if(side_select==0) side=2;
if(side_select==1) side=3;
if(side_select==2) side=0;
//if(side_select==3) side=1;
} else
if(side==5){//right to bot
bot=1;
if(side_select==0) side=0;
if(side_select==1) side=2;
if(side_select==2) side=3;
//if(side_select==3) side=1;
}
else
if(side==2){//right to back
back=1;
if(side_select==0) side=0;
//if(side_select==1) side=1;
if(side_select==1) side=5;
if(side_select==2) side=4;} else
if(side==3){//right to front
front=1;
if(side_select==0) side=0;
//if(side_select==1) side=1;
if(side_select==1) side=5;
if(side_select==2) side=4;}
} else//bot
if(left==1){// LEFT
left=0;
if(side==4){//left to top
top=1;
//if(side_select==0) side=2;
if(side_select==0) side=3;
if(side_select==1) side=2;
if(side_select==2) side=1;} else
if(side==5){//left to bot
bot=1;
//if(side_select==0) side=0;
if(side_select==0) side=2;
if(side_select==1) side=3;
if(side_select==2) side=1;} else
if(side==2){//left to back
back=1;
//if(side_select==0) side=0;
if(side_select==0) side=1;
if(side_select==1) side=5;
if(side_select==2) side=4;} else
if(side==3){//left to front
front=1;
//if(side_select==0) side=0;
if(side_select==0) side=1;
if(side_select==1) side=5;
if(side_select==2) side=4;}
} else//bot
if(front==1){// front
front=0;
if(side==4){//front to top
top=1;
if(side_select==0) side=2;
//if(side_select==1) side=3;
if(side_select==1) side=0;
if(side_select==2) side=1;} else
if(side==5){//front to bot
bot=1;
if(side_select==0) side=0;
if(side_select==1) side=2;
//if(side_select==2) side=3;
if(side_select==2) side=1;} else
if(side==0){//front to left
left=1;
if(side_select==0) side=2;
// if(side_select==1) side=3;
if(side_select==1) side=5;
if(side_select==2) side=4;} else
if(side==1){//front to right
right=1;
if(side_select==0) side=2;
// if(side_select==1) side=3;
if(side_select==1) side=5;
if(side_select==2) side=4;}
} else//bot
if(back==1){// back
back=0;
if(side==4){//back to top
top=1;
//if(side_select==0) side=2;
if(side_select==0) side=3;
if(side_select==1) side=0;
if(side_select==2) side=1;} else
if(side==5){//back to bot
bot=1;
if(side_select==0) side=0;
//if(side_select==1) side=2;
if(side_select==1) side=3;
if(side_select==2) side=1;} else
if(side==0){//back to left
left=1;
//if(side_select==0) side=2;
if(side_select==0) side=3;
if(side_select==1) side=5;
if(side_select==2) side=4;} else
if(side==1){//back to right
right=1;
//if(side_select==0) side=2;
if(side_select==0) side=3;
if(side_select==1) side=5;
if(side_select==2) side=4;}
} //bot
// for(yy=0; yy<8; yy++)
//for(xx=0; xx<8; xx++)
//LED(LED_Old[yy], xx, yy-oldpullback[yy], 0, 0, 0);
for(xx=0; xx<8; xx++){
oldpullback[xx]=0;
pullback[xx]=0;}
folderaddr[0]=-8;
folderaddr[1]=-7;
folderaddr[2]=-6;
folderaddr[3]=-5;
folderaddr[4]=-4;
folderaddr[5]=-3;
folderaddr[6]=-2;
folderaddr[7]=-1;
}//pullback==7
}//folderaddr==7
if(folderaddr[7]!=7)
// if(folderaddr[7]=7) // REMOVED !
for(zz=0; zz<8; zz++)
folderaddr[zz] = folderaddr[zz]+1;
}//while
}//folder
void bouncyvTwo(){//****bouncyTwo****bouncyTwo****bouncyTwo****bouncyTwo****bouncyTwo****bouncyTwo****bouncyTwo
int wipex, wipey, wipez, ranr, rang, ranb, select, oldx[50], oldy[50], oldz[50];
int x[50], y[50], z[50], addr, ledcount=20, direct, direcTwo;
int xx[50], yy[50], zz[50];
int xbit=1, ybit=1, zbit=1;
for(addr=0; addr<ledcount+1; addr++){
oldx[addr]=0;
oldy[addr]=0;
oldz[addr]=0;
x[addr]=0;
y[addr]=0;
z[addr]=0;
xx[addr]=0;
yy[addr]=0;
zz[addr]=0;
}
start=millis();
while(millis()-start<15000){
direct = random(3);
for(addr=1; addr<ledcount+1; addr++){
LED(oldx[addr], oldy[addr],oldz[addr], 0,0,0);
LED(x[addr], y[addr], z[addr], xx[addr],yy[addr],zz[addr]);
}
for(addr=1; addr<ledcount+1; addr++){
oldx[addr]=x[addr];
oldy[addr]=y[addr];
oldz[addr]=z[addr];
}
delay(20);
//direcTwo=random(3);
//if(direcTwo==1)
if(direct==0)
x[0]= x[0]+xbit;
if(direct==1)
y[0]= y[0]+ybit;
if(direct==2)
z[0]= z[0]+zbit;
if(direct==3)
x[0]= x[0]-xbit;
if(direct==4)
y[0]= y[0]-ybit;
if(direct==5)
z[0]= z[0]-zbit;
if(x[0]>7){
xbit=-1;
x[0]=7;
xx[0]=random(16);
yy[0]=random(16);
zz[0]=0;
//wipe_out();
}
if(x[0]<0){
xbit=1;
x[0]=0;
xx[0]=random(16);
yy[0]=0;
zz[0]=random(16);
//wipe_out();
}
if(y[0]>7){
ybit=-1;
y[0]=7;
xx[0]=0;
yy[0]=random(16);
zz[0]=random(16);
//wipe_out();
}
if(y[0]<0){
ybit=1;
y[0]=0;
xx[0]=0;
yy[0]=random(16);
zz[0]=random(16);
//wipe_out();
}
if(z[0]>7){
zbit=-1;
z[0]=7;
xx[0]=random(16);
yy[0]=0;
zz[0]=random(16);
//wipe_out();
}
if(z[0]<0){
zbit=1;
z[0]=0;
xx[0]=random(16);
yy[0]=random(16);
zz[0]=0;
//wipe_out();
}
for(addr=ledcount; addr>0; addr--){
x[addr]=x[addr-1];
y[addr]=y[addr-1];
z[addr]=z[addr-1];
xx[addr]=xx[addr-1];
yy[addr]=yy[addr-1];
zz[addr]=zz[addr-1];
}
}//while
}//bouncyv2
void sinwaveTwo(){//*****sinewaveTwo*****sinewaveTwo*****sinewaveTwo*****sinewaveTwo*****sinewaveTwo*****sinewaveTwo
int sinewavearray[8], addr, sinemult[8], colselect, rr=0, gg=0, bb=15, addrt;
int sinewavearrayOLD[8], select, subZ=-7, subT=7, multi=0;//random(-1, 2);
sinewavearray[0]=0;
sinemult[0]=1;
sinewavearray[1]=1;
sinemult[1]=1;
sinewavearray[2]=2;
sinemult[2]=1;
sinewavearray[3]=3;
sinemult[3]=1;
sinewavearray[4]=4;
sinemult[4]=1;
sinewavearray[5]=5;
sinemult[5]=1;
sinewavearray[6]=6;
sinemult[6]=1;
sinewavearray[7]=7;
sinemult[7]=1;
start=millis();
while(millis()-start<15000){
for(addr=0; addr<8; addr++){
if(sinewavearray[addr]==7){
sinemult[addr]=-1;
}
if(sinewavearray[addr]==0){
sinemult[addr]=1;
}
sinewavearray[addr] = sinewavearray[addr] + sinemult[addr];
}//addr
if(sinewavearray[0]==7){
select=random(3);
if(select==0){
rr=random(1, 16);
gg=random(1, 16);
bb=0;}
if(select==1){
rr=random(1, 16);
gg=0;
bb=random(1, 16);}
if(select==2){
rr=0;
gg=random(1, 16);
bb=random(1, 16);}
/*
if(multi==1)
multi=0;
else
multi=1;
*/
}
for(addr=0; addr<8; addr++){
LED(sinewavearrayOLD[addr], addr, 0, 0, 0, 0);
LED(sinewavearrayOLD[addr], 0, addr, 0, 0, 0);
LED(sinewavearrayOLD[addr], subT-addr, 7, 0, 0, 0);
LED(sinewavearrayOLD[addr], 7, subT-addr, 0, 0, 0);
LED(sinewavearray[addr], addr, 0, rr, gg, bb);
LED(sinewavearray[addr], 0, addr, rr, gg, bb);
LED(sinewavearray[addr], subT-addr,7, rr, gg, bb);
LED(sinewavearray[addr], 7, subT-addr, rr, gg, bb);
}//}
for(addr=1; addr<7; addr++){
LED(sinewavearrayOLD[addr+multi*1], addr, 1, 0, 0, 0);
LED(sinewavearrayOLD[addr+multi*1], 1, addr, 0, 0, 0);
LED(sinewavearrayOLD[addr+multi*1], subT-addr, 6, 0, 0, 0);
LED(sinewavearrayOLD[addr+multi*1], 6, subT-addr, 0, 0, 0);
LED(sinewavearray[addr+multi*1], addr, 1, rr, gg, bb);
LED(sinewavearray[addr+multi*1], 1, addr, rr, gg, bb);
LED(sinewavearray[addr+multi*1], subT-addr,6, rr, gg, bb);
LED(sinewavearray[addr+multi*1], 6, subT-addr, rr, gg, bb);
}
for(addr=2; addr<6; addr++){
LED(sinewavearrayOLD[addr+multi*2], addr, 2, 0, 0, 0);
LED(sinewavearrayOLD[addr+multi*2], 2, addr, 0, 0, 0);
LED(sinewavearrayOLD[addr+multi*2], subT-addr, 5, 0, 0, 0);
LED(sinewavearrayOLD[addr+multi*2], 5, subT-addr, 0, 0, 0);
LED(sinewavearray[addr+multi*2], addr, 2, rr, gg, bb);
LED(sinewavearray[addr+multi*2], 2, addr, rr, gg, bb);
LED(sinewavearray[addr+multi*2], subT-addr,5, rr, gg, bb);
LED(sinewavearray[addr+multi*2], 5, subT-addr, rr, gg, bb);
}
for(addr=3; addr<5; addr++){
LED(sinewavearrayOLD[addr+multi*3], addr, 3, 0, 0, 0);
LED(sinewavearrayOLD[addr+multi*3], 3, addr, 0, 0, 0);
LED(sinewavearrayOLD[addr+multi*3], subT-addr, 4, 0, 0, 0);
LED(sinewavearrayOLD[addr+multi*3], 4, subT-addr, 0, 0, 0);
LED(sinewavearray[addr+multi*3], addr, 3, rr, gg, bb);
LED(sinewavearray[addr+multi*3], 3, addr, rr, gg, bb);
LED(sinewavearray[addr+multi*3], subT-addr,4, rr, gg, bb);
LED(sinewavearray[addr+multi*3], 4, subT-addr, rr, gg, bb);
}
for(addr=0; addr<8; addr++)
sinewavearrayOLD[addr]=sinewavearray[addr];
delay(30);
}//while
}//SinewaveTwo
void color_wheel(){
int xx, yy, zz, ww, rr=1, gg=1, bb=1, ranx, rany, swiper;
start=millis();
while(millis()-start<100000){
swiper=random(3);
ranx=random(16);
rany=random(16);
for(xx=0;xx<8;xx++){
for(yy=0;yy<8;yy++){
for(zz=0;zz<8;zz++){
LED(xx, yy, zz, ranx, 0, rany);
}}
delay(50);
}
ranx=random(16);
rany=random(16);
for(xx=7;xx>=0;xx--){
for(yy=0;yy<8;yy++){
for(zz=0;zz<8;zz++){
LED(xx,yy, zz, ranx, rany, 0);
}}
delay(50);
}
ranx=random(16);
rany=random(16);
for(xx=0;xx<8;xx++){
for(yy=0;yy<8;yy++){
for(zz=0;zz<8;zz++){
LED(xx,yy, zz, 0, ranx, rany);
}}
delay(50);
}
ranx=random(16);
rany=random(16);
for(xx=7;xx>=0;xx--){
for(yy=0;yy<8;yy++){
for(zz=0;zz<8;zz++){
LED(xx,yy, zz, rany, ranx, 0);
}}
delay(50);
}
}//while
}//color wheel
void color_wheelTWO(){//*****colorWheelTwo*****colorWheelTwo*****colorWheelTwo*****colorWheelTwo*****colorWheelTwo
int xx, yy, zz, ww, rr=1, gg=1, bb=1, ranx, rany ,ranz, select, swiper;
start=millis();
while(millis()-start<10000){
swiper=random(6);
select=random(3);
if(select==0){
ranx=0;
rany=random(16);
ranz=random(16);}
if(select==1){
ranx=random(16);
rany=0;
ranz=random(16);}
if(select==2){
ranx=random(16);
rany=random(16);
ranz=0;}
if(swiper==0){
for(yy=0;yy<8;yy++){//left to right
for(xx=0;xx<8;xx++){
for(zz=0;zz<8;zz++){
LED(xx, yy, zz, ranx, ranz, rany);
}}
delay(30);
}}
if(swiper==1){//bot to top
for(xx=0;xx<8;xx++){
for(yy=0;yy<8;yy++){
for(zz=0;zz<8;zz++){
LED(xx, yy, zz, ranx, ranz, rany);
}}
delay(30);
}}
if(swiper==2){//back to front
for(zz=0;zz<8;zz++){
for(xx=0;xx<8;xx++){
for(yy=0;yy<8;yy++){
LED(xx, yy, zz, ranx, ranz, rany);
}}
delay(30);
}}
if(swiper==3){
for(yy=7;yy>=0;yy--){//right to left
for(xx=0;xx<8;xx++){
for(zz=0;zz<8;zz++){
LED(xx, yy, zz, ranx, ranz, rany);
}}
delay(30);
}}
if(swiper==4){//top to bot
for(xx=7;xx>=0;xx--){
for(yy=0;yy<8;yy++){
for(zz=0;zz<8;zz++){
LED(xx, yy, zz, ranx, ranz, rany);
}}
delay(30);
}}
if(swiper==5){//front to back
for(zz=7;zz>=0;zz--){
for(xx=0;xx<8;xx++){
for(yy=0;yy<8;yy++){
LED(xx, yy, zz, ranx, ranz, rany);
}}
delay(30);
}}
}//while
}//color wheel
// Harlem Shake Harlem Shake Harlem Shake Harlem Shake Harlem Shake
void harlem_shake(){
int greenx = random(1,7),greeny = random(1,7),bluex = random(1,7),bluey = random(1,7),redx = random(1,7),redy = random(1,7);
int greenmult=1, bluemult=1, redmult=1;
int greenmulty=1, bluemulty=1, redmulty=1;
int oredx, oredy,obluex,obluey,ogreenx,ogreeny, cb1=15,cb2=0,cr1=15,cr2=0,cg1=15,cg2=0;
int time_counter=10, timemult=2;
int m;
int c1=1,c2=1,c3=1,xmult=1,ymult=1,zmult=1,x=4,y=4,z=4,color_select, xo, yo, zo;
int c21=1,c22=1,c23=1,x2mult=1,y2mult=1,z2mult=1,x2=2,y2=2,z2=2,color_select2, x2o, y2o, z2o;
int counter, i, j, k;
// *************** THREE STROKES ************************
for(counter=0; counter<150; counter++){ // RED LOOP HERE
for(i=0; i<8; i++){
LED(i,oredx,oredx,0,0,0);
}
for(i=0; i<8; i++){
LED(i,redx,redx,15,0,0);
}
oredx=redx;
oredy=redy;
for(i=100; i>time_counter; i--)
delay(1);
time_counter=time_counter+timemult;
if(time_counter>100||time_counter<10)
timemult=timemult*-1;
if(redy>6 || redy<1){
redmulty=redmulty*-1;
}
if(redx>6 || redx<1){
redmult=redmult*-1;
cr1=random(16);
cr2=random(16);
}
redy=redy+redmulty;
redx=redx+redmult;
}//counter
for(counter=0; counter<85; counter++){ // RED AND GREEN LOOP HERE
for(i=0; i<8; i++){
LED(i,oredx,oredx,0,0,0);
LED(ogreenx,i,ogreeny,0,0,0);
}
for(i=0; i<8; i++){
LED(i,redx,redx,15,0,0);
LED(greenx,i,greeny,0,15,0);
}
ogreenx=greenx;
ogreeny=greeny;
oredx=redx;
oredy=redy;
for(i=100; i>time_counter; i--)
delay(1);
time_counter=time_counter+timemult;
if(time_counter>100||time_counter<10)
timemult=timemult*-1;
if(greeny>6 || greeny<1)
greenmulty=greenmulty*-1;
if(redy>6 || redy<1){
redmulty=redmulty*-1;
}
if(greenx>6 || greenx<1){
greenmult=greenmult*-1;
greeny = greeny + greenmulty;
cg1=random(16);
cg2=random(16);
}
if(redx>6 || redx<1){
redmult=redmult*-1;
cr1=random(16);
cr2=random(16);
}
greenx=greenx+greenmult;
redy=redy+redmulty;
redx=redx+redmult;
}//counter
for(counter=0; counter<85; counter++){ // RED GREEN AND BLUE LOOP HERE
for(i=0; i<8; i++){
LED(i,oredx,oredx,0,0,0);
LED(obluey,obluex,i,0,0,0);
LED(ogreenx,i,ogreeny,0,0,0);
}
for(i=0; i<8; i++){
LED(i,redx,redx,15,0,0);
LED(bluey,bluex,i,0,0,15);
LED(greenx,i,greeny,0,15,0);
}
ogreenx=greenx;
ogreeny=greeny;
obluex=bluex;
obluey=bluey;
oredx=redx;
oredy=redy;
for(i=100; i>time_counter; i--)
delay(1);
time_counter=time_counter+timemult;
if(time_counter>100||time_counter<10)
timemult=timemult*-1;
if(greeny>6 || greeny<1)
greenmulty=greenmulty*-1;
if(bluey>6 || bluey<1)
bluemulty=bluemulty*-1;
if(redy>6 || redy<1){
redmulty=redmulty*-1;
}
if(greenx>6 || greenx<1){
greenmult=greenmult*-1;
greeny = greeny + greenmulty;
cg1=random(16);
cg2=random(16);
}
if(bluex>6 || bluex<1){
bluemult=bluemult*-1;
bluey=bluey+bluemulty;
cb1=random(16);
cb2=random(16);
}
if(redx>6 || redx<1){
redmult=redmult*-1;
cr1=random(16);
cr2=random(16);
}
greenx=greenx+greenmult;
bluex=bluex+bluemult;
redy=redy+redmulty;
redx=redx+redmult;
}//counter
clean();
//******************** Flash White *****************
/*
for(counter=0; counter<3; counter++){ // LOOP HERE
for(i=0; i<8; i++)
for(j=0; j<8; j++)
for(k=0; k<8; k++)
LED(i,j,k,15,15,15);
delay(50);
clean();
//for(i=0; i<8; i++)
//for(j=0; j<8; j++)
//for(k=0; k<8; k++)
//LED(i,j,k,0,0,0);
delay(50);
}//counter
clean();
*/
// ************ MULTI ALL LAYER SWEEP **********************
for(m=0; m<3; m++){ //LOOP HERE
for(i=0; i<8; i++)
for(j=0; j<8; j++)
for(k=0; k<8; k++)
LED(i,j,k,0,random(16),random(16));
for(i=7; i>=0; i--)
for(j=0; j<8; j++)
for(k=0; k<8; k++)
LED(i,j,k,random(16),0,random(16));
for(i=0; i<8; i++)
for(j=0; j<8; j++)
for(k=0; k<8; k++)
LED(i,j,k,random(16),random(16),0);
for(i=7; i>=0; i--)
for(j=0; j<8; j++)
for(k=0; k<8; k++)
LED(i,j,k,random(16),0,random(16));
}
clean();
// ******************* TUTI FRUITI ***********************
for(m=0; m<10; m++){ // LOOP HERE
for(k=0; k<225; k++){
LED(random(8),random(8),random(8),random(16),random(16),0);
LED(random(8),random(8),random(8),random(16),0 ,random(16));
LED(random(8),random(8),random(8),0, random(16),random(16));
}
for(k=0; k<150; k++){
LED(random(8),random(8),random(8),0,0,0);
}
}//m
clean();
// ************ TWO CUBES CHASING EACHOTHER ********************
color_select=random(0,3);
if(color_select==0){
c1 = 0;
c2 = random(0,16);
c3 = random(0,16);}
if(color_select==1){
c1 = random(0,16);
c2 = 0;
c3 = random(0,16);}
if(color_select==2){
c1 = random(0,16);
c2 = random(0,16);
c3 = 0;}
color_select2=random(0,3);
if(color_select2==0){
c21 = 0;
c22 = random(0,16);
c23 = random(0,16);}
if(color_select2==1){
c21 = random(0,16);
c22 = 0;
c23 = random(0,16);}
if(color_select2==2){
c21 = random(0,16);
c22 = random(0,16);
c23 = 0;}
for(counter=0; counter<200; counter++){ // LOOP HERE
LED(xo,yo,zo,0,0,0);
LED(xo+1,yo,zo,0,0,0);
LED(xo+2,yo,zo,0,0,0);
LED(xo-1,yo,zo,0,0,0);
LED(xo-2,yo,zo,0,0,0);
LED(xo,yo+1,zo,0,0,0);
LED(xo,yo-1,zo,0,0,0);
LED(xo,yo+2,zo,0,0,0);
LED(xo,yo-2,zo,0,0,0);
LED(xo,yo,zo-1,0,0,0);
LED(xo,yo,zo+1,0,0,0);
LED(xo,yo,zo-2,0,0,0);
LED(xo,yo,zo+2,0,0,0);
LED(x2o,y2o,z2o,0,0,0);
LED(x2o+1,y2o,z2o,0,0,0);
LED(x2o+2,y2o,z2o,0,0,0);
LED(x2o-1,y2o,z2o,0,0,0);
LED(x2o-2,y2o,z2o,0,0,0);
LED(x2o,y2o+1,z2o,0,0,0);
LED(x2o,y2o-1,z2o,0,0,0);
LED(x2o,y2o+2,z2o,0,0,0);
LED(x2o,y2o-2,z2o,0,0,0);
LED(x2o,y2o,z2o-1,0,0,0);
LED(x2o,y2o,z2o+1,0,0,0);
LED(x2o,y2o,z2o-2,0,0,0);
LED(x2o,y2o,z2o+2,0,0,0);
LED(xo+1,yo+1,zo,0,0,0);
LED(xo+1,yo-1,zo,0,0,0);
LED(xo-1,yo+1,zo,0,0,0);
LED(xo-1,yo-1,zo,0,0,0);
LED(xo+1,yo+1,zo+1,0,0,0);
LED(xo+1,yo-1,zo+1,0,0,0);
LED(xo-1,yo+1,zo+1,0,0,0);
LED(xo-1,yo-1,zo+1,0,0,0);
LED(xo+1,yo+1,zo-1,0,0,0);
LED(xo+1,yo-1,zo-1,0,0,0);
LED(xo-1,yo+1,zo-1,0,0,0);
LED(xo-1,yo-1,zo-1,0,0,0);
LED(x2o+1,y2o+1,z2o,0,0,0);
LED(x2o+1,y2o-1,z2o,0,0,0);
LED(x2o-1,y2o+1,z2o,0,0,0);
LED(x2o-1,y2o-1,z2o,0,0,0);
LED(x2o+1,y2o+1,z2o+1,0,0,0);
LED(x2o+1,y2o-1,z2o+1,0,0,0);
LED(x2o-1,y2o+1,z2o+1,0,0,0);
LED(x2o-1,y2o-1,z2o+1,0,0,0);
LED(x2o+1,y2o+1,z2o-1,0,0,0);
LED(x2o+1,y2o-1,z2o-1,0,0,0);
LED(x2o-1,y2o+1,z2o-1,0,0,0);
LED(x2o-1,y2o-1,z2o-1,0,0,0);
LED(x,y,z,c1,c2,c3);
LED(x,y,z-1,c1,c2,c3);
LED(x,y,z+1,c1,c2,c3);
LED(x,y,z-2,c1,c2,c3);
LED(x,y,z+2,c1,c2,c3);
LED(x+1,y,z,c1,c2,c3);
LED(x-1,y,z,c1,c2,c3);
LED(x,y+1,z,c1,c2,c3);
LED(x,y-1,z,c1,c2,c3);
LED(x+2,y,z,c1,c2,c3);
LED(x-2,y,z,c1,c2,c3);
LED(x,y+2,z,c1,c2,c3);
LED(x,y-2,z,c1,c2,c3);
LED(x+1,y+1,z,c1,c2,c3);
LED(x+1,y-1,z,c1,c2,c3);
LED(x-1,y+1,z,c1,c2,c3);
LED(x-1,y-1,z,c1,c2,c3);
LED(x+1,y+1,z+1,c1,c2,c3);
LED(x+1,y-1,z+1,c1,c2,c3);
LED(x-1,y+1,z+1,c1,c2,c3);
LED(x-1,y-1,z+1,c1,c2,c3);
LED(x+1,y+1,z-1,c1,c2,c3);
LED(x+1,y-1,z-1,c1,c2,c3);
LED(x-1,y+1,z-1,c1,c2,c3);
LED(x-1,y-1,z-1,c1,c2,c3);
LED(x2,y2,z2,c21,c22,c23);
LED(x2,y2,z2-1,c21,c22,c23);
LED(x2,y2,z2+1,c21,c22,c23);
LED(x2,y2,z2-2,c21,c22,c23);
LED(x2,y2,z2+2,c21,c22,c23);
LED(x2+1,y2,z2,c21,c22,c23);
LED(x2-1,y2,z2,c21,c22,c23);
LED(x2,y2+1,z2,c21,c22,c23);
LED(x2,y2-1,z2,c21,c22,c23);
LED(x2+2,y2,z2,c21,c22,c23);
LED(x2-2,y2,z2,c21,c22,c23);
LED(x2,y2+2,z2,c21,c22,c23);
LED(x2,y2-2,z2,c21,c22,c23);
LED(x2+1,y2+1,z2,c21,c22,c23);
LED(x2+1,y2-1,z2,c21,c22,c23);
LED(x2-1,y2+1,z2,c21,c22,c23);
LED(x2-1,y2-1,z2,c21,c22,c23);
LED(x2+1,y2+1,z2+1,c21,c22,c23);
LED(x2+1,y2-1,z2+1,c21,c22,c23);
LED(x2-1,y2+1,z2+1,c21,c22,c23);
LED(x2-1,y2-1,z2+1,c21,c22,c23);
LED(x2+1,y2+1,z2-1,c21,c22,c23);
LED(x2+1,y2-1,z2-1,c21,c22,c23);
LED(x2-1,y2+1,z2-1,c21,c22,c23);
LED(x2-1,y2-1,z2-1,c21,c22,c23);
x2o=x2;
y2o=y2;
z2o=z2;
xo=x;
yo=y;
zo=z;
delay(45);
x = x+xmult;
y= y+ymult;
z= z+zmult;
x2 = x2+x2mult;
y2= y2+y2mult;
z2= z2+z2mult;
if(x>=7){
//x=7;
xmult=random(-1,1);
}
if(y>=7){
//y=7;
ymult=random(-1,1);}
if(z>=7){
//z=7;
zmult=random(-1,1);}
if(x<=0){
//x=0;
xmult=random(0,2);}
if(y<=0){
//y=0;
ymult=random(0,2);}
if(z<=0){
//z=0;
zmult=random(0,2);
}
if(x2>=7){
//x=7;
x2mult=random(-1,1);
}
if(y2>=7){
//y=7;
y2mult=random(-1,1);}
if(z2>=7){
//z=7;
z2mult=random(-1,1);}
if(x2<=0){
//x=0;
x2mult=random(0,2);}
if(y2<=0){
//y=0;
y2mult=random(0,2);}
if(z<=0){
//z=0;
z2mult=random(0,2);
}
}//counter counter counter counter counter
// ****************** STACKS ************************
for(counter=0; counter<7; counter++){ // LOOP HERE
color_select=random(0,3);
if(color_select==0){
c1 = 0;
c2 = random(0,16);
c3 = random(0,16);}
if(color_select==1){
c1 = random(0,16);
c2 = 0;
c3 = random(0,16);}
if(color_select==2){
c1 = random(0,16);
c2 = random(0,16);
c3 = 0;}
int num1=-1, num2=-4, num3=-6, num4=-10;
for(m=0; m<20; m++){
num1++;
num2++;
num3++;
num4++;
for(i=3; i<5; i++){
LED(num1, i,3,0,0,0);
LED(num1, 3,i,0,0,0);
LED(num1, 4,i,0,0,0);
LED(num1, i,4,0,0,0);
}
for(i=3; i<5; i++){
LED(num1+1, i,4,c1,c2,c3);
LED(num1+1, 4,i,c1,c2,c3);
LED(num1+1, 3,i,c1,c2,c3);
LED(num1+1, i,3,c1,c2,c3);
}
for(i=2; i<6; i++){
LED(num2, i,2,0,0,0);
LED(num2, 2,i,0,0,0);
LED(num2, 5,i,0,0,0);
LED(num2, i,5,0,0,0);
}
for(i=2; i<6; i++){
LED(num2+1, i,2,c1,c2,c3);
LED(num2+1, 2,i,c1,c2,c3);
LED(num2+1, 5,i,c1,c2,c3);
LED(num2+1, i,5,c1,c2,c3);
}
for(i=1; i<7; i++){
LED(num3, i,1,0,0,0);
LED(num3, 1,i,0,0,0);
LED(num3, 6,i,0,0,0);
LED(num3, i,6,0,0,0);
}
for(i=1; i<7; i++){
LED(num3+1, i,1,c1,c2,c3);
LED(num3+1, 1,i,c1,c2,c3);
LED(num3+1, 6,i,c1,c2,c3);
LED(num3+1, i,6,c1,c2,c3);
}
for(i=0; i<8; i++){
LED(num4, i,0,0,0,0);
LED(num4, 0,i,0,0,0);
LED(num4, 7,i,0,0,0);
LED(num4, i,7,0,0,0);
}
for(i=0; i<8; i++){
LED(num4+1, i,0,c1,c2,c3);
LED(num4+1, 0,i,c1,c2,c3);
LED(num4+1, 7,i,c1,c2,c3);
LED(num4+1, i,7,c1,c2,c3);
}
//delay(1);
}//m
num1=8;
num2=11;
num3=13;
num4=17;
for(m=0; m<20; m++){
num1--;
num2--;
num3--;
num4--;
for(i=3; i<5; i++){
LED(num1, i,3,0,0,0);
LED(num1, 3,i,0,0,0);
LED(num1, 4,i,0,0,0);
LED(num1, i,4,0,0,0);
}
for(i=3; i<5; i++){
LED(num1-1, i,4,0,0,15);
LED(num1-1, 4,i,0,0,15);
LED(num1-1, 3,i,0,0,15);
LED(num1-1, i,3,0,0,15);
}
for(i=2; i<6; i++){
LED(num2, i,2,0,0,0);
LED(num2, 2,i,0,0,0);
LED(num2, 5,i,0,0,0);
LED(num2, i,5,0,0,0);
}
for(i=2; i<6; i++){
LED(num2-1, i,2,0,0,15);
LED(num2-1, 2,i,0,0,15);
LED(num2-1, 5,i,0,0,15);
LED(num2-1, i,5,0,0,15);
}
for(i=1; i<7; i++){
LED(num3, i,1,0,0,0);
LED(num3, 1,i,0,0,0);
LED(num3, 6,i,0,0,0);
LED(num3, i,6,0,0,0);
}
for(i=1; i<7; i++){
LED(num3-1, i,1,0,0,15);
LED(num3-1, 1,i,0,0,15);
LED(num3-1, 6,i,0,0,15);
LED(num3-1, i,6,0,0,15);
}
for(i=0; i<8; i++){
LED(num4, i,0,0,0,0);
LED(num4, 0,i,0,0,0);
LED(num4, 7,i,0,0,0);
LED(num4, i,7,0,0,0);
}
for(i=0; i<8; i++){
LED(num4-1, i,0,0,0,15);
LED(num4-1, 0,i,0,0,15);
LED(num4-1, 7,i,0,0,15);
LED(num4-1, i,7,0,0,15);
}
//delay(1);
}//m
}//counter
}//End harlem SHake
// ********* CLEAN UP ***************
void clean(){
int ii, jj, kk;
for(ii=0; ii<8; ii++)
for(jj=0; jj<8; jj++)
for(kk=0; kk<8; kk++)
LED(ii,jj,kk,0,0,0);
}
void wave(){
byte repeatTimes = 5; // number of time to repeat wave
// sart wave Form
globalRed = rand()%16;
globalGreen = rand()%16;
globalBlue = rand()%16;
// start wave
defineWave(0,0,0,0);
defineWave(0,0,0,1);
defineWave(0,0,1,2);
defineWave(0,1,2,3);
defineWave(1,2,3,4);
defineWave(2,3,4,5);
defineWave(3,4,5,6);
defineWave(4,5,6,7);
for (int x=0;x<repeatTimes;x++){
for (int y=0;y<2;y++){ // number of times to repeat wave in same colour
for (int i=8;i<21;i++){
defineWave(i-3,i-2,i-1,i);
}// end first wave
}// end second (y) wave
globalRed = rand()%16;
globalGreen = rand()%16;
globalBlue = rand()%16;
}// end Repeat
}// End Wave
void defineWave(byte rowSel1, byte rowSel2, byte rowSel3, byte rowSel4){ //
byte waveForms[21][4] = {
{ 0, 0, 0, 0}, // 0 Start
{ 0, 0, 0, 1}, // 1
{ 0, 0, 1, 2}, // 2
{ 0, 1, 2, 3}, // 3
{ 0, 1, 3, 4}, // 4
{ 0, 2, 4, 5}, // 5
{ 0, 2, 4, 6}, // 6
{ 0, 3, 5, 7}, // 7 Loop from here
{ 1, 3, 4, 6}, // 8
{ 2, 3, 4, 5}, // 9
{ 3, 3, 3, 4}, // 10
{ 4, 4, 4, 3}, // 11
{ 5, 4, 3, 2}, // 12
{ 6, 4, 3, 1}, // 13
{ 7, 4, 2, 0}, // 14
{ 6, 4, 3, 1}, // 15
{ 5, 4, 3, 2}, // 16
{ 4, 4, 4, 3}, // 17
{ 3, 3, 3, 4}, // 18
{ 2, 3, 4, 5}, // 19
{ 1, 3, 4, 6} // 20 Loop back to 7
};
// first wave
halfWave (0, waveForms[rowSel1][0], waveForms[rowSel1][1], waveForms[rowSel1][2], waveForms[rowSel1][3]);
halfWave (1, waveForms[rowSel2][0], waveForms[rowSel2][1], waveForms[rowSel2][2], waveForms[rowSel2][3]);
halfWave (2, waveForms[rowSel3][0], waveForms[rowSel3][1], waveForms[rowSel3][2], waveForms[rowSel3][3]);
halfWave (3, waveForms[rowSel4][0], waveForms[rowSel4][1], waveForms[rowSel4][2], waveForms[rowSel4][3]);
halfWave (4, waveForms[rowSel4][0], waveForms[rowSel4][1], waveForms[rowSel4][2], waveForms[rowSel4][3]);
halfWave (5, waveForms[rowSel3][0], waveForms[rowSel3][1], waveForms[rowSel3][2], waveForms[rowSel3][3]);
halfWave (6, waveForms[rowSel2][0], waveForms[rowSel2][1], waveForms[rowSel2][2], waveForms[rowSel2][3]);
halfWave (7, waveForms[rowSel1][0], waveForms[rowSel1][1], waveForms[rowSel1][2], waveForms[rowSel1][3]);
delay (50);
cleanWave (0, waveForms[rowSel1][0], waveForms[rowSel1][1], waveForms[rowSel1][2], waveForms[rowSel1][3]);
cleanWave (1, waveForms[rowSel2][0], waveForms[rowSel2][1], waveForms[rowSel2][2], waveForms[rowSel2][3]);
cleanWave (2, waveForms[rowSel3][0], waveForms[rowSel3][1], waveForms[rowSel3][2], waveForms[rowSel3][3]);
cleanWave (3, waveForms[rowSel4][0], waveForms[rowSel4][1], waveForms[rowSel4][2], waveForms[rowSel4][3]);
cleanWave (4, waveForms[rowSel4][0], waveForms[rowSel4][1], waveForms[rowSel4][2], waveForms[rowSel4][3]);
cleanWave (5, waveForms[rowSel3][0], waveForms[rowSel3][1], waveForms[rowSel3][2], waveForms[rowSel3][3]);
cleanWave (6, waveForms[rowSel2][0], waveForms[rowSel2][1], waveForms[rowSel2][2], waveForms[rowSel2][3]);
cleanWave (7, waveForms[rowSel1][0], waveForms[rowSel1][1], waveForms[rowSel1][2], waveForms[rowSel1][3]);
} // /end defineWave
void halfWave(int rowNo, int lay1, int lay2, int lay3, int lay4){
LED(lay1, 0, rowNo, globalRed, globalGreen, globalBlue);
LED(lay2, 1, rowNo, globalRed, globalGreen, globalBlue);
LED(lay3, 2, rowNo, globalRed, globalGreen, globalBlue);
LED(lay4, 3, rowNo, globalRed, globalGreen, globalBlue);
LED(lay4, 4, rowNo, globalRed, globalGreen, globalBlue);
LED(lay3, 5, rowNo, globalRed, globalGreen, globalBlue);
LED(lay2, 6, rowNo, globalRed, globalGreen, globalBlue);
LED(lay1, 7, rowNo, globalRed, globalGreen, globalBlue);
}// End halfWave
void cleanWave(int rowNo, int lay1, int lay2, int lay3, int lay4){
LED(lay1, 0, rowNo, 0,0,0);
LED(lay2, 1, rowNo, 0,0,0);
LED(lay3, 2, rowNo, 0,0,0);
LED(lay4, 3, rowNo, 0,0,0);
LED(lay4, 4, rowNo, 0,0,0);
LED(lay3, 5, rowNo, 0,0,0);
LED(lay2, 6, rowNo, 0,0,0);
LED(lay1, 7, rowNo, 0,0,0);
}// End halfWave
最后
以上就是典雅鞋垫为你收集整理的arduino-rgb888-code-02的全部内容,希望文章能够帮你解决arduino-rgb888-code-02所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复