Ivan Yohuno
/
neopixel_spi
Code to work with NeoPixels
main.cpp
- Committer:
- ivanyohuno
- Date:
- 2015-04-22
- Revision:
- 0:c350fa2f0c19
- Child:
- 1:42b43fa7362f
File content as of revision 0:c350fa2f0c19:
#include "mbed.h" #include <string.h> #include <stdio.h> #include "NeoStrip.h" /* neopixel_spi v03 Created By: Ivan Yohuno SSID: 200717683 Notes: -Code to be run on WS2812 neopixel LEDs, can run with a single pixel or a strip of max 8 leds connected together -Single LED can be connected to power source of 5V but if connected to 5V logic will need to be shifted up from 3.3V to 5V Features: -SetRGBPixel // sets colour of one RGB Pixel (the first pixel connected), generally used for testing. Colour is a mix of 3 8 bit values of red, green and blue -SetRGBStrip // sets colour of RGB strip of 8 -setRGBStrips //sets colours of 4 RGB strips of 8 colours 2D 4x3 matrix: {{room 1 strip red, room 1 strip green, room 1 strip blue}, {room 2 strip red, room 2 strip green, room 3 strip blue}, {room 3 strip red, room 3 strip green, room 3 strip blue} } -SetRGBPixels // sets an RGB strip of 8 to individual colours using a 2D 8x3 matrix colours 2D 8x3 matrix: {{1st pixel red, 1st pixel blue, 1st pixel green}, {2nd pixel red, 2nd pixel blue, 2nd pixel green}, {3rd pixel red, 3rd pixel blue, 3rd pixel green}, {4th pixel red, 4th pixel blue, 4th pixel green}, {5th pixel red, 5th pixel blue, 5th pixel green}, {6th pixel red, 6th pixel blue, 6th pixel green}, {7th pixel red, 7th pixel blue, 7th pixel green}, {8th pixel red, 8th pixel blue, 8th pixel green} } -setRGBAll // sets 4 RGB strips of 8 to individual colours using a 3D 8x4x3 matrix colours 2D 8x4x3 matrix: {room1{1st pixel red, 1st pixel blue, 1st pixel green}, {2nd pixel red, 2nd pixel blue, 2nd pixel green}, {3rd pixel red, 3rd pixel blue, 3rd pixel green}, {4th pixel red, 4th pixel blue, 4th pixel green}, {5th pixel red, 5th pixel blue, 5th pixel green}, {6th pixel red, 6th pixel blue, 6th pixel green}, {7th pixel red, 7th pixel blue, 7th pixel green}, {8th pixel red, 8th pixel blue, 8th pixel green} room2{1st pixel red, 1st pixel blue, 1st pixel green}, {2nd pixel red, 2nd pixel blue, 2nd pixel green}, {3rd pixel red, 3rd pixel blue, 3rd pixel green}, {4th pixel red, 4th pixel blue, 4th pixel green}, {5th pixel red, 5th pixel blue, 5th pixel green}, {6th pixel red, 6th pixel blue, 6th pixel green}, {7th pixel red, 7th pixel blue, 7th pixel green}, {8th pixel red, 8th pixel blue, 8th pixel green} room3{1st pixel red, 1st pixel blue, 1st pixel green}, {2nd pixel red, 2nd pixel blue, 2nd pixel green}, {3rd pixel red, 3rd pixel blue, 3rd pixel green}, {4th pixel red, 4th pixel blue, 4th pixel green}, {5th pixel red, 5th pixel blue, 5th pixel green}, {6th pixel red, 6th pixel blue, 6th pixel green}, {7th pixel red, 7th pixel blue, 7th pixel green}, {8th pixel red, 8th pixel blue, 8th pixel green} room4{1st pixel red, 1st pixel blue, 1st pixel green}, {2nd pixel red, 2nd pixel blue, 2nd pixel green}, {3rd pixel red, 3rd pixel blue, 3rd pixel green}, {4th pixel red, 4th pixel blue, 4th pixel green}, {5th pixel red, 5th pixel blue, 5th pixel green}, {6th pixel red, 6th pixel blue, 6th pixel green}, {7th pixel red, 7th pixel blue, 7th pixel green}, {8th pixel red, 8th pixel blue, 8th pixel green} } */ //function declarations void setRGBPixel(int r, int g, int b); //sets colour of one RGB Pixel void setRGBStrip(int r, int g, int b); //sets colour of a strip of 8 RGB Pixels void setRGBStrips(int colours[4][3]); //sets colour of 4 strips of 8 RGB Pixels void setRGBPixels(int colours[8][3]); //sets sequence of colours for a strip of 8 RGB Pixels void setRGBAll(int colours[4][8][3]); //sets a sequence of colours for 4 strips of 8 RGB Pixels void spi_init(); //initializes SPI pin at correct bit length and bit rate int * decimalToBinary(int n); //converts a decimal value between 0 and 255 to an 8 bit binary array of 0xF00 (0) and 0xFF0 (1) //initialize pins DigitalOut volt(p16); //pin for LV voltage SPI spi(p5, p6, p7);//pin for SPI communication - p5 MOSI p5 MISO p6 SCLK NeoStrip strip(p5,8); int main() { volt = 1; //use either function } void setRGBStrip(int r, int g, int b){ int r_array[8]; int g_array[8]; int b_array[8]; memcpy(r_array, decimalToBinary(r), sizeof(r_array)); memcpy(g_array, decimalToBinary(g), sizeof(g_array)); memcpy(b_array, decimalToBinary(b), sizeof(b_array)); //send commands to LED Driver //initialize SPI spi_init(); //LED0 //set green bits spi.write(g_array[7]); //set g7 bit spi.write(g_array[6]); //set g6 bit spi.write(g_array[5]); //set g5 bit spi.write(g_array[4]); //set g4 bit spi.write(g_array[3]); //set g3 bit spi.write(g_array[2]); //set g2 bit spi.write(g_array[1]); //set g1 bit spi.write(g_array[0]);//set g0 bit //set red bits spi.write(r_array[7]);//set r7 bit spi.write(r_array[6]); //set r6 bit spi.write(r_array[5]); //set r5 bit spi.write(r_array[4]); //set r4 bit spi.write(r_array[3]); //set r3 bit spi.write(r_array[2]); //set r2 bit spi.write(r_array[1]); //set r1 bit spi.write(r_array[0]); //set r0 bit //set blue bits spi.write(b_array[7]); //set b7 bit spi.write(b_array[6]); //set b6 bit spi.write(b_array[5]); //set b5 bit spi.write(b_array[4]); //set b4 bit spi.write(b_array[3]); //set b3 bit spi.write(b_array[2]); //set b2 bit spi.write(b_array[1]); //set b1 bit spi.write(b_array[0]); //set b0 bit //LED1 //set green bits spi.write(g_array[7]); //set g7 bit spi.write(g_array[6]); //set g6 bit spi.write(g_array[5]); //set g5 bit spi.write(g_array[4]); //set g4 bit spi.write(g_array[3]); //set g3 bit spi.write(g_array[2]); //set g2 bit spi.write(g_array[1]); //set g1 bit spi.write(g_array[0]);//set g0 bit //set red bits spi.write(r_array[7]);//set r7 bit spi.write(r_array[6]); //set r6 bit spi.write(r_array[5]); //set r5 bit spi.write(r_array[4]); //set r4 bit spi.write(r_array[3]); //set r3 bit spi.write(r_array[2]); //set r2 bit spi.write(r_array[1]); //set r1 bit spi.write(r_array[0]); //set r0 bit //set blue bits spi.write(b_array[7]); //set b7 bit spi.write(b_array[6]); //set b6 bit spi.write(b_array[5]); //set b5 bit spi.write(b_array[4]); //set b4 bit spi.write(b_array[3]); //set b3 bit spi.write(b_array[2]); //set b2 bit spi.write(b_array[1]); //set b1 bit spi.write(b_array[0]); //set b0 bit //LED2 //set green bits spi.write(g_array[7]); //set g7 bit spi.write(g_array[6]); //set g6 bit spi.write(g_array[5]); //set g5 bit spi.write(g_array[4]); //set g4 bit spi.write(g_array[3]); //set g3 bit spi.write(g_array[2]); //set g2 bit spi.write(g_array[1]); //set g1 bit spi.write(g_array[0]);//set g0 bit //set red bits spi.write(r_array[7]);//set r7 bit spi.write(r_array[6]); //set r6 bit spi.write(r_array[5]); //set r5 bit spi.write(r_array[4]); //set r4 bit spi.write(r_array[3]); //set r3 bit spi.write(r_array[2]); //set r2 bit spi.write(r_array[1]); //set r1 bit spi.write(r_array[0]); //set r0 bit //set blue bits spi.write(b_array[7]); //set b7 bit spi.write(b_array[6]); //set b6 bit spi.write(b_array[5]); //set b5 bit spi.write(b_array[4]); //set b4 bit spi.write(b_array[3]); //set b3 bit spi.write(b_array[2]); //set b2 bit spi.write(b_array[1]); //set b1 bit spi.write(b_array[0]); //set b0 bit //LED3 //set green bits spi.write(g_array[7]); //set g7 bit spi.write(g_array[6]); //set g6 bit spi.write(g_array[5]); //set g5 bit spi.write(g_array[4]); //set g4 bit spi.write(g_array[3]); //set g3 bit spi.write(g_array[2]); //set g2 bit spi.write(g_array[1]); //set g1 bit spi.write(g_array[0]);//set g0 bit //set red bits spi.write(r_array[7]);//set r7 bit spi.write(r_array[6]); //set r6 bit spi.write(r_array[5]); //set r5 bit spi.write(r_array[4]); //set r4 bit spi.write(r_array[3]); //set r3 bit spi.write(r_array[2]); //set r2 bit spi.write(r_array[1]); //set r1 bit spi.write(r_array[0]); //set r0 bit //set blue bits spi.write(b_array[7]); //set b7 bit spi.write(b_array[6]); //set b6 bit spi.write(b_array[5]); //set b5 bit spi.write(b_array[4]); //set b4 bit spi.write(b_array[3]); //set b3 bit spi.write(b_array[2]); //set b2 bit spi.write(b_array[1]); //set b1 bit spi.write(b_array[0]); //set b0 bit //LED4 //set green bits spi.write(g_array[7]); //set g7 bit spi.write(g_array[6]); //set g6 bit spi.write(g_array[5]); //set g5 bit spi.write(g_array[4]); //set g4 bit spi.write(g_array[3]); //set g3 bit spi.write(g_array[2]); //set g2 bit spi.write(g_array[1]); //set g1 bit spi.write(g_array[0]);//set g0 bit //set red bits spi.write(r_array[7]);//set r7 bit spi.write(r_array[6]); //set r6 bit spi.write(r_array[5]); //set r5 bit spi.write(r_array[4]); //set r4 bit spi.write(r_array[3]); //set r3 bit spi.write(r_array[2]); //set r2 bit spi.write(r_array[1]); //set r1 bit spi.write(r_array[0]); //set r0 bit //set blue bits spi.write(b_array[7]); //set b7 bit spi.write(b_array[6]); //set b6 bit spi.write(b_array[5]); //set b5 bit spi.write(b_array[4]); //set b4 bit spi.write(b_array[3]); //set b3 bit spi.write(b_array[2]); //set b2 bit spi.write(b_array[1]); //set b1 bit spi.write(b_array[0]); //set b0 bit //LED5 //set green bits spi.write(g_array[7]); //set g7 bit spi.write(g_array[6]); //set g6 bit spi.write(g_array[5]); //set g5 bit spi.write(g_array[4]); //set g4 bit spi.write(g_array[3]); //set g3 bit spi.write(g_array[2]); //set g2 bit spi.write(g_array[1]); //set g1 bit spi.write(g_array[0]);//set g0 bit //set red bits spi.write(r_array[7]);//set r7 bit spi.write(r_array[6]); //set r6 bit spi.write(r_array[5]); //set r5 bit spi.write(r_array[4]); //set r4 bit spi.write(r_array[3]); //set r3 bit spi.write(r_array[2]); //set r2 bit spi.write(r_array[1]); //set r1 bit spi.write(r_array[0]); //set r0 bit //set blue bits spi.write(b_array[7]); //set b7 bit spi.write(b_array[6]); //set b6 bit spi.write(b_array[5]); //set b5 bit spi.write(b_array[4]); //set b4 bit spi.write(b_array[3]); //set b3 bit spi.write(b_array[2]); //set b2 bit spi.write(b_array[1]); //set b1 bit spi.write(b_array[0]); //set b0 bit //LED6 //set green bits spi.write(g_array[7]); //set g7 bit spi.write(g_array[6]); //set g6 bit spi.write(g_array[5]); //set g5 bit spi.write(g_array[4]); //set g4 bit spi.write(g_array[3]); //set g3 bit spi.write(g_array[2]); //set g2 bit spi.write(g_array[1]); //set g1 bit spi.write(g_array[0]);//set g0 bit //set red bits spi.write(r_array[7]);//set r7 bit spi.write(r_array[6]); //set r6 bit spi.write(r_array[5]); //set r5 bit spi.write(r_array[4]); //set r4 bit spi.write(r_array[3]); //set r3 bit spi.write(r_array[2]); //set r2 bit spi.write(r_array[1]); //set r1 bit spi.write(r_array[0]); //set r0 bit //set blue bits spi.write(b_array[7]); //set b7 bit spi.write(b_array[6]); //set b6 bit spi.write(b_array[5]); //set b5 bit spi.write(b_array[4]); //set b4 bit spi.write(b_array[3]); //set b3 bit spi.write(b_array[2]); //set b2 bit spi.write(b_array[1]); //set b1 bit spi.write(b_array[0]); //set b0 bit //LED7 //set green bits /* spi.write(g_array[7]); //set g7 bit spi.write(g_array[6]); //set g6 bit spi.write(g_array[5]); //set g5 bit spi.write(g_array[4]); //set g4 bit spi.write(g_array[3]); //set g3 bit spi.write(g_array[2]); //set g2 bit spi.write(g_array[1]); //set g1 bit spi.write(g_array[0]);//set g0 bit //set red bits spi.write(r_array[7]);//set r7 bit spi.write(r_array[6]); //set r6 bit spi.write(r_array[5]); //set r5 bit spi.write(r_array[4]); //set r4 bit spi.write(r_array[3]); //set r3 bit spi.write(r_array[2]); //set r2 bit spi.write(r_array[1]); //set r1 bit spi.write(r_array[0]); //set r0 bit //set blue bits spi.write(b_array[7]); //set b7 bit spi.write(b_array[6]); //set b6 bit spi.write(b_array[5]); //set b5 bit spi.write(b_array[4]); //set b4 bit spi.write(b_array[3]); //set b3 bit spi.write(b_array[2]); //set b2 bit spi.write(b_array[1]); //set b1 bit spi.write(b_array[0]); //set b0 bit */ //wait for latch wait_us(60); } void setRGBPixel(int r, int g, int b){ //translate int values to array of 0xF00 (0) and 0xFF0 (1) binary int r_array[8]; int g_array[8]; int b_array[8]; memcpy(r_array, decimalToBinary(r), sizeof(r_array)); memcpy(g_array, decimalToBinary(g), sizeof(g_array)); memcpy(b_array, decimalToBinary(b), sizeof(b_array)); //send commands to LED Driver //initialize SPI spi_init(); //set green bits spi.write(g_array[7]); //set g7 bit spi.write(g_array[6]); //set g6 bit spi.write(g_array[5]); //set g5 bit spi.write(g_array[4]); //set g4 bit spi.write(g_array[3]); //set g3 bit spi.write(g_array[2]); //set g2 bit spi.write(g_array[1]); //set g1 bit spi.write(g_array[0]);//set g0 bit //set red bits spi.write(r_array[7]);//set r7 bit spi.write(r_array[6]); //set r6 bit spi.write(r_array[5]); //set r5 bit spi.write(r_array[4]); //set r4 bit spi.write(r_array[3]); //set r3 bit spi.write(r_array[2]); //set r2 bit spi.write(r_array[1]); //set r1 bit spi.write(r_array[0]); //set r0 bit //set blue bits spi.write(b_array[7]); //set b7 bit spi.write(b_array[6]); //set b6 bit spi.write(b_array[5]); //set b5 bit spi.write(b_array[4]); //set b4 bit spi.write(b_array[3]); //set b3 bit spi.write(b_array[2]); //set b2 bit spi.write(b_array[1]); //set b1 bit spi.write(b_array[0]); //set b0 bit //wait for latch wait_us(60); } void setRGBPixels(int colours[8][3]){ //translate int values to array of 0xF00 (0) and 0xFF0 (1) binary int r0_array[8]; //LED0 int g0_array[8]; int b0_array[8]; memcpy(r0_array, decimalToBinary(colours[0][0]), sizeof(r0_array)); memcpy(g0_array, decimalToBinary(colours[0][1]), sizeof(g0_array)); memcpy(b0_array, decimalToBinary(colours[0][2]), sizeof(b0_array)); int r1_array[8]; //LED1 int g1_array[8]; int b1_array[8]; memcpy(r1_array, decimalToBinary(colours[1][0]), sizeof(r1_array)); memcpy(g1_array, decimalToBinary(colours[1][1]), sizeof(g1_array)); memcpy(b1_array, decimalToBinary(colours[1][2]), sizeof(b1_array)); int r2_array[8]; //LED2 int g2_array[8]; int b2_array[8]; memcpy(r2_array, decimalToBinary(colours[2][0]), sizeof(r2_array)); memcpy(g2_array, decimalToBinary(colours[2][1]), sizeof(g2_array)); memcpy(b2_array, decimalToBinary(colours[2][2]), sizeof(b2_array)); int r3_array[8]; //LED3 int g3_array[8]; int b3_array[8]; memcpy(r3_array, decimalToBinary(colours[3][0]), sizeof(r3_array)); memcpy(g3_array, decimalToBinary(colours[3][1]), sizeof(g3_array)); memcpy(b3_array, decimalToBinary(colours[3][2]), sizeof(b3_array)); int r4_array[8]; //LED4 int g4_array[8]; int b4_array[8]; memcpy(r4_array, decimalToBinary(colours[4][0]), sizeof(r4_array)); memcpy(g4_array, decimalToBinary(colours[4][1]), sizeof(g4_array)); memcpy(b4_array, decimalToBinary(colours[4][2]), sizeof(b4_array)); int r5_array[8]; //LED5 int g5_array[8]; int b5_array[8]; memcpy(r5_array, decimalToBinary(colours[5][0]), sizeof(r5_array)); memcpy(g5_array, decimalToBinary(colours[5][1]), sizeof(g5_array)); memcpy(b5_array, decimalToBinary(colours[5][2]), sizeof(b5_array)); int r6_array[8]; //LED6 int g6_array[8]; int b6_array[8]; memcpy(r6_array, decimalToBinary(colours[6][0]), sizeof(r6_array)); memcpy(g6_array, decimalToBinary(colours[6][1]), sizeof(g6_array)); memcpy(b6_array, decimalToBinary(colours[6][2]), sizeof(b6_array)); int r7_array[8]; //LED7 int g7_array[8]; int b7_array[8]; memcpy(r7_array, decimalToBinary(colours[7][0]), sizeof(r7_array)); memcpy(g7_array, decimalToBinary(colours[7][1]), sizeof(g7_array)); memcpy(b7_array, decimalToBinary(colours[7][2]), sizeof(b7_array)); //send commands to LED Driver //initialize SPI spi_init(); //LED0 //set green bits spi.write(g0_array[7]); //set g7 bit spi.write(g0_array[6]); //set g6 bit spi.write(g0_array[5]); //set g5 bit spi.write(g0_array[4]); //set g4 bit spi.write(g0_array[3]); //set g3 bit spi.write(g0_array[2]); //set g2 bit spi.write(g0_array[1]); //set g1 bit spi.write(g0_array[0]);//set g0 bit //set red bits spi.write(r0_array[7]);//set r7 bit spi.write(r0_array[6]); //set r6 bit spi.write(r0_array[5]); //set r5 bit spi.write(r0_array[4]); //set r4 bit spi.write(r0_array[3]); //set r3 bit spi.write(r0_array[2]); //set r2 bit spi.write(r0_array[1]); //set r1 bit spi.write(r0_array[0]); //set r0 bit //set blue bits spi.write(b0_array[7]); //set b7 bit spi.write(b0_array[6]); //set b6 bit spi.write(b0_array[5]); //set b5 bit spi.write(b0_array[4]); //set b4 bit spi.write(b0_array[3]); //set b3 bit spi.write(b0_array[2]); //set b2 bit spi.write(b0_array[1]); //set b1 bit spi.write(b0_array[0]); //set b0 bit //LED1 //set green bits spi.write(g1_array[7]); //set g7 bit spi.write(g1_array[6]); //set g6 bit spi.write(g1_array[5]); //set g5 bit spi.write(g1_array[4]); //set g4 bit spi.write(g1_array[3]); //set g3 bit spi.write(g1_array[2]); //set g2 bit spi.write(g1_array[1]); //set g1 bit spi.write(g1_array[0]);//set g0 bit //set red bits spi.write(r1_array[7]);//set r7 bit spi.write(r1_array[6]); //set r6 bit spi.write(r1_array[5]); //set r5 bit spi.write(r1_array[4]); //set r4 bit spi.write(r1_array[3]); //set r3 bit spi.write(r1_array[2]); //set r2 bit spi.write(r1_array[1]); //set r1 bit spi.write(r1_array[0]); //set r0 bit //set blue bits spi.write(b1_array[7]); //set b7 bit spi.write(b1_array[6]); //set b6 bit spi.write(b1_array[5]); //set b5 bit spi.write(b1_array[4]); //set b4 bit spi.write(b1_array[3]); //set b3 bit spi.write(b1_array[2]); //set b2 bit spi.write(b1_array[1]); //set b1 bit spi.write(b1_array[0]); //set b0 bit //LED2 //set green bits spi.write(g2_array[7]); //set g7 bit spi.write(g2_array[6]); //set g6 bit spi.write(g2_array[5]); //set g5 bit spi.write(g2_array[4]); //set g4 bit spi.write(g2_array[3]); //set g3 bit spi.write(g2_array[2]); //set g2 bit spi.write(g2_array[1]); //set g1 bit spi.write(g2_array[0]);//set g0 bit //set red bits spi.write(r2_array[7]);//set r7 bit spi.write(r2_array[6]); //set r6 bit spi.write(r2_array[5]); //set r5 bit spi.write(r2_array[4]); //set r4 bit spi.write(r2_array[3]); //set r3 bit spi.write(r2_array[2]); //set r2 bit spi.write(r2_array[1]); //set r1 bit spi.write(r2_array[0]); //set r0 bit //set blue bits spi.write(b2_array[7]); //set b7 bit spi.write(b2_array[6]); //set b6 bit spi.write(b2_array[5]); //set b5 bit spi.write(b2_array[4]); //set b4 bit spi.write(b2_array[3]); //set b3 bit spi.write(b2_array[2]); //set b2 bit spi.write(b2_array[1]); //set b1 bit spi.write(b2_array[0]); //set b0 bit //LED3 //set green bits spi.write(g3_array[7]); //set g7 bit spi.write(g3_array[6]); //set g6 bit spi.write(g3_array[5]); //set g5 bit spi.write(g3_array[4]); //set g4 bit spi.write(g3_array[3]); //set g3 bit spi.write(g3_array[2]); //set g2 bit spi.write(g3_array[1]); //set g1 bit spi.write(g3_array[0]);//set g0 bit //set red bits spi.write(r3_array[7]);//set r7 bit spi.write(r3_array[6]); //set r6 bit spi.write(r3_array[5]); //set r5 bit spi.write(r3_array[4]); //set r4 bit spi.write(r3_array[3]); //set r3 bit spi.write(r3_array[2]); //set r2 bit spi.write(r3_array[1]); //set r1 bit spi.write(r3_array[0]); //set r0 bit //set blue bits spi.write(b3_array[7]); //set b7 bit spi.write(b3_array[6]); //set b6 bit spi.write(b3_array[5]); //set b5 bit spi.write(b3_array[4]); //set b4 bit spi.write(b3_array[3]); //set b3 bit spi.write(b3_array[2]); //set b2 bit spi.write(b3_array[1]); //set b1 bit spi.write(b3_array[0]); //set b0 bit //LED4 //set green bits spi.write(g4_array[7]); //set g7 bit spi.write(g4_array[6]); //set g6 bit spi.write(g4_array[5]); //set g5 bit spi.write(g4_array[4]); //set g4 bit spi.write(g4_array[3]); //set g3 bit spi.write(g4_array[2]); //set g2 bit spi.write(g4_array[1]); //set g1 bit spi.write(g4_array[0]);//set g0 bit //set red bits spi.write(r4_array[7]);//set r7 bit spi.write(r4_array[6]); //set r6 bit spi.write(r4_array[5]); //set r5 bit spi.write(r4_array[4]); //set r4 bit spi.write(r4_array[3]); //set r3 bit spi.write(r4_array[2]); //set r2 bit spi.write(r4_array[1]); //set r1 bit spi.write(r4_array[0]); //set r0 bit //set blue bits spi.write(b4_array[7]); //set b7 bit spi.write(b4_array[6]); //set b6 bit spi.write(b4_array[5]); //set b5 bit spi.write(b4_array[4]); //set b4 bit spi.write(b4_array[3]); //set b3 bit spi.write(b4_array[2]); //set b2 bit spi.write(b4_array[1]); //set b1 bit spi.write(b4_array[0]); //set b0 bit //LED5 //set green bits spi.write(g5_array[7]); //set g7 bit spi.write(g5_array[6]); //set g6 bit spi.write(g5_array[5]); //set g5 bit spi.write(g5_array[4]); //set g4 bit spi.write(g5_array[3]); //set g3 bit spi.write(g5_array[2]); //set g2 bit spi.write(g5_array[1]); //set g1 bit spi.write(g5_array[0]);//set g0 bit //set red bits spi.write(r5_array[7]);//set r7 bit spi.write(r5_array[6]); //set r6 bit spi.write(r5_array[5]); //set r5 bit spi.write(r5_array[4]); //set r4 bit spi.write(r5_array[3]); //set r3 bit spi.write(r5_array[2]); //set r2 bit spi.write(r5_array[1]); //set r1 bit spi.write(r5_array[0]); //set r0 bit //set blue bits spi.write(b5_array[7]); //set b7 bit spi.write(b5_array[6]); //set b6 bit spi.write(b5_array[5]); //set b5 bit spi.write(b5_array[4]); //set b4 bit spi.write(b5_array[3]); //set b3 bit spi.write(b5_array[2]); //set b2 bit spi.write(b5_array[1]); //set b1 bit spi.write(b5_array[0]); //set b0 bit //LED6 //set green bits spi.write(g6_array[7]); //set g7 bit spi.write(g6_array[6]); //set g6 bit spi.write(g6_array[5]); //set g5 bit spi.write(g6_array[4]); //set g4 bit spi.write(g6_array[3]); //set g3 bit spi.write(g6_array[2]); //set g2 bit spi.write(g6_array[1]); //set g1 bit spi.write(g6_array[0]);//set g0 bit //set red bits spi.write(r6_array[7]);//set r7 bit spi.write(r6_array[6]); //set r6 bit spi.write(r6_array[5]); //set r5 bit spi.write(r6_array[4]); //set r4 bit spi.write(r6_array[3]); //set r3 bit spi.write(r6_array[2]); //set r2 bit spi.write(r6_array[1]); //set r1 bit spi.write(r6_array[0]); //set r0 bit //set blue bits spi.write(b6_array[7]); //set b7 bit spi.write(b6_array[6]); //set b6 bit spi.write(b6_array[5]); //set b5 bit spi.write(b6_array[4]); //set b4 bit spi.write(b6_array[3]); //set b3 bit spi.write(b6_array[2]); //set b2 bit spi.write(b6_array[1]); //set b1 bit spi.write(b6_array[0]); //set b0 bit //LED7 //set green bits spi.write(g7_array[7]); //set g7 bit spi.write(g7_array[6]); //set g6 bit spi.write(g7_array[5]); //set g5 bit spi.write(g7_array[4]); //set g4 bit spi.write(g7_array[3]); //set g3 bit spi.write(g7_array[2]); //set g2 bit spi.write(g7_array[1]); //set g1 bit spi.write(g7_array[0]);//set g0 bit //set red bits spi.write(r7_array[7]);//set r7 bit spi.write(r7_array[6]); //set r6 bit spi.write(r7_array[5]); //set r5 bit spi.write(r7_array[4]); //set r4 bit spi.write(r7_array[3]); //set r3 bit spi.write(r7_array[2]); //set r2 bit spi.write(r7_array[1]); //set r1 bit spi.write(r7_array[0]); //set r0 bit //set blue bits spi.write(b7_array[7]); //set b7 bit spi.write(b7_array[6]); //set b6 bit spi.write(b7_array[5]); //set b5 bit spi.write(b7_array[4]); //set b4 bit spi.write(b7_array[3]); //set b3 bit spi.write(b7_array[2]); //set b2 bit spi.write(b7_array[1]); //set b1 bit spi.write(b7_array[0]); //set b0 bit //wait for latch wait_us(60); } void setRGBStrips(int colours[4][3]){ //translate int values to array of 0xF00 (0) and 0xFF0 (1) binary int r0_array[8]; //room1 int g0_array[8]; int b0_array[8]; memcpy(r0_array, decimalToBinary(colours[0][0]), sizeof(r0_array)); memcpy(g0_array, decimalToBinary(colours[0][1]), sizeof(g0_array)); memcpy(b0_array, decimalToBinary(colours[0][2]), sizeof(b0_array)); int r1_array[8]; //room2 int g1_array[8]; int b1_array[8]; memcpy(r1_array, decimalToBinary(colours[1][0]), sizeof(r1_array)); memcpy(g1_array, decimalToBinary(colours[1][1]), sizeof(g1_array)); memcpy(b1_array, decimalToBinary(colours[1][2]), sizeof(b1_array)); int r2_array[8]; //room3 int g2_array[8]; int b2_array[8]; memcpy(r2_array, decimalToBinary(colours[2][0]), sizeof(r2_array)); memcpy(g2_array, decimalToBinary(colours[2][1]), sizeof(g2_array)); memcpy(b2_array, decimalToBinary(colours[2][2]), sizeof(b2_array)); int r3_array[8]; //room4 int g3_array[8]; int b3_array[8]; memcpy(r3_array, decimalToBinary(colours[3][0]), sizeof(r3_array)); memcpy(g3_array, decimalToBinary(colours[3][1]), sizeof(g3_array)); memcpy(b3_array, decimalToBinary(colours[3][2]), sizeof(b3_array)); //send commands to LED Driver //initialize SPI spi_init(); //room 1 //LED0 //set green bits spi.write(g0_array[7]); //set g7 bit spi.write(g0_array[6]); //set g6 bit spi.write(g0_array[5]); //set g5 bit spi.write(g0_array[4]); //set g4 bit spi.write(g0_array[3]); //set g3 bit spi.write(g0_array[2]); //set g2 bit spi.write(g0_array[1]); //set g1 bit spi.write(g0_array[0]);//set g0 bit //set red bits spi.write(r0_array[7]);//set r7 bit spi.write(r0_array[6]); //set r6 bit spi.write(r0_array[5]); //set r5 bit spi.write(r0_array[4]); //set r4 bit spi.write(r0_array[3]); //set r3 bit spi.write(r0_array[2]); //set r2 bit spi.write(r0_array[1]); //set r1 bit spi.write(r0_array[0]); //set r0 bit //set blue bits spi.write(b0_array[7]); //set b7 bit spi.write(b0_array[6]); //set b6 bit spi.write(b0_array[5]); //set b5 bit spi.write(b0_array[4]); //set b4 bit spi.write(b0_array[3]); //set b3 bit spi.write(b0_array[2]); //set b2 bit spi.write(b0_array[1]); //set b1 bit spi.write(b0_array[0]); //set b0 bit //LED1 //set green bits spi.write(g0_array[7]); //set g7 bit spi.write(g0_array[6]); //set g6 bit spi.write(g0_array[5]); //set g5 bit spi.write(g0_array[4]); //set g4 bit spi.write(g0_array[3]); //set g3 bit spi.write(g0_array[2]); //set g2 bit spi.write(g0_array[1]); //set g1 bit spi.write(g0_array[0]);//set g0 bit //set red bits spi.write(r0_array[7]);//set r7 bit spi.write(r0_array[6]); //set r6 bit spi.write(r0_array[5]); //set r5 bit spi.write(r0_array[4]); //set r4 bit spi.write(r0_array[3]); //set r3 bit spi.write(r0_array[2]); //set r2 bit spi.write(r0_array[1]); //set r1 bit spi.write(r0_array[0]); //set r0 bit //set blue bits spi.write(b0_array[7]); //set b7 bit spi.write(b0_array[6]); //set b6 bit spi.write(b0_array[5]); //set b5 bit spi.write(b0_array[4]); //set b4 bit spi.write(b0_array[3]); //set b3 bit spi.write(b0_array[2]); //set b2 bit spi.write(b0_array[1]); //set b1 bit spi.write(b0_array[0]); //set b0 bit //LED2 //set green bits spi.write(g0_array[7]); //set g7 bit spi.write(g0_array[6]); //set g6 bit spi.write(g0_array[5]); //set g5 bit spi.write(g0_array[4]); //set g4 bit spi.write(g0_array[3]); //set g3 bit spi.write(g0_array[2]); //set g2 bit spi.write(g0_array[1]); //set g1 bit spi.write(g0_array[0]);//set g0 bit //set red bits spi.write(r0_array[7]);//set r7 bit spi.write(r0_array[6]); //set r6 bit spi.write(r0_array[5]); //set r5 bit spi.write(r0_array[4]); //set r4 bit spi.write(r0_array[3]); //set r3 bit spi.write(r0_array[2]); //set r2 bit spi.write(r0_array[1]); //set r1 bit spi.write(r0_array[0]); //set r0 bit //set blue bits spi.write(b0_array[7]); //set b7 bit spi.write(b0_array[6]); //set b6 bit spi.write(b0_array[5]); //set b5 bit spi.write(b0_array[4]); //set b4 bit spi.write(b0_array[3]); //set b3 bit spi.write(b0_array[2]); //set b2 bit spi.write(b0_array[1]); //set b1 bit spi.write(b0_array[0]); //set b0 bit //LED3 //set green bits spi.write(g0_array[7]); //set g7 bit spi.write(g0_array[6]); //set g6 bit spi.write(g0_array[5]); //set g5 bit spi.write(g0_array[4]); //set g4 bit spi.write(g0_array[3]); //set g3 bit spi.write(g0_array[2]); //set g2 bit spi.write(g0_array[1]); //set g1 bit spi.write(g0_array[0]);//set g0 bit //set red bits spi.write(r0_array[7]);//set r7 bit spi.write(r0_array[6]); //set r6 bit spi.write(r0_array[5]); //set r5 bit spi.write(r0_array[4]); //set r4 bit spi.write(r0_array[3]); //set r3 bit spi.write(r0_array[2]); //set r2 bit spi.write(r0_array[1]); //set r1 bit spi.write(r0_array[0]); //set r0 bit //set blue bits spi.write(b0_array[7]); //set b7 bit spi.write(b0_array[6]); //set b6 bit spi.write(b0_array[5]); //set b5 bit spi.write(b0_array[4]); //set b4 bit spi.write(b0_array[3]); //set b3 bit spi.write(b0_array[2]); //set b2 bit spi.write(b0_array[1]); //set b1 bit spi.write(b0_array[0]); //set b0 bit //LED4 //set green bits spi.write(g0_array[7]); //set g7 bit spi.write(g0_array[6]); //set g6 bit spi.write(g0_array[5]); //set g5 bit spi.write(g0_array[4]); //set g4 bit spi.write(g0_array[3]); //set g3 bit spi.write(g0_array[2]); //set g2 bit spi.write(g0_array[1]); //set g1 bit spi.write(g0_array[0]);//set g0 bit //set red bits spi.write(r0_array[7]);//set r7 bit spi.write(r0_array[6]); //set r6 bit spi.write(r0_array[5]); //set r5 bit spi.write(r0_array[4]); //set r4 bit spi.write(r0_array[3]); //set r3 bit spi.write(r0_array[2]); //set r2 bit spi.write(r0_array[1]); //set r1 bit spi.write(r0_array[0]); //set r0 bit //set blue bits spi.write(b0_array[7]); //set b7 bit spi.write(b0_array[6]); //set b6 bit spi.write(b0_array[5]); //set b5 bit spi.write(b0_array[4]); //set b4 bit spi.write(b0_array[3]); //set b3 bit spi.write(b0_array[2]); //set b2 bit spi.write(b0_array[1]); //set b1 bit spi.write(b0_array[0]); //set b0 bit //LED5 //set green bits spi.write(g0_array[7]); //set g7 bit spi.write(g0_array[6]); //set g6 bit spi.write(g0_array[5]); //set g5 bit spi.write(g0_array[4]); //set g4 bit spi.write(g0_array[3]); //set g3 bit spi.write(g0_array[2]); //set g2 bit spi.write(g0_array[1]); //set g1 bit spi.write(g0_array[0]);//set g0 bit //set red bits spi.write(r0_array[7]);//set r7 bit spi.write(r0_array[6]); //set r6 bit spi.write(r0_array[5]); //set r5 bit spi.write(r0_array[4]); //set r4 bit spi.write(r0_array[3]); //set r3 bit spi.write(r0_array[2]); //set r2 bit spi.write(r0_array[1]); //set r1 bit spi.write(r0_array[0]); //set r0 bit //set blue bits spi.write(b0_array[7]); //set b7 bit spi.write(b0_array[6]); //set b6 bit spi.write(b0_array[5]); //set b5 bit spi.write(b0_array[4]); //set b4 bit spi.write(b0_array[3]); //set b3 bit spi.write(b0_array[2]); //set b2 bit spi.write(b0_array[1]); //set b1 bit spi.write(b0_array[0]); //set b0 bit //LED6 //set green bits spi.write(g0_array[7]); //set g7 bit spi.write(g0_array[6]); //set g6 bit spi.write(g0_array[5]); //set g5 bit spi.write(g0_array[4]); //set g4 bit spi.write(g0_array[3]); //set g3 bit spi.write(g0_array[2]); //set g2 bit spi.write(g0_array[1]); //set g1 bit spi.write(g0_array[0]);//set g0 bit //set red bits spi.write(r0_array[7]);//set r7 bit spi.write(r0_array[6]); //set r6 bit spi.write(r0_array[5]); //set r5 bit spi.write(r0_array[4]); //set r4 bit spi.write(r0_array[3]); //set r3 bit spi.write(r0_array[2]); //set r2 bit spi.write(r0_array[1]); //set r1 bit spi.write(r0_array[0]); //set r0 bit //set blue bits spi.write(b0_array[7]); //set b7 bit spi.write(b0_array[6]); //set b6 bit spi.write(b0_array[5]); //set b5 bit spi.write(b0_array[4]); //set b4 bit spi.write(b0_array[3]); //set b3 bit spi.write(b0_array[2]); //set b2 bit spi.write(b0_array[1]); //set b1 bit spi.write(b0_array[0]); //set b0 bit //LED7 //set green bits spi.write(g0_array[7]); //set g7 bit spi.write(g0_array[6]); //set g6 bit spi.write(g0_array[5]); //set g5 bit spi.write(g0_array[4]); //set g4 bit spi.write(g0_array[3]); //set g3 bit spi.write(g0_array[2]); //set g2 bit spi.write(g0_array[1]); //set g1 bit spi.write(g0_array[0]);//set g0 bit //set red bits spi.write(r0_array[7]);//set r7 bit spi.write(r0_array[6]); //set r6 bit spi.write(r0_array[5]); //set r5 bit spi.write(r0_array[4]); //set r4 bit spi.write(r0_array[3]); //set r3 bit spi.write(r0_array[2]); //set r2 bit spi.write(r0_array[1]); //set r1 bit spi.write(r0_array[0]); //set r0 bit //set blue bits spi.write(b0_array[7]); //set b7 bit spi.write(b0_array[6]); //set b6 bit spi.write(b0_array[5]); //set b5 bit spi.write(b0_array[4]); //set b4 bit spi.write(b0_array[3]); //set b3 bit spi.write(b0_array[2]); //set b2 bit spi.write(b0_array[1]); //set b1 bit spi.write(b0_array[0]); //set b0 bit //room 2 //LED0 //set green bits spi.write(g1_array[7]); //set g7 bit spi.write(g1_array[6]); //set g6 bit spi.write(g1_array[5]); //set g5 bit spi.write(g1_array[4]); //set g4 bit spi.write(g1_array[3]); //set g3 bit spi.write(g1_array[2]); //set g2 bit spi.write(g1_array[1]); //set g1 bit spi.write(g1_array[0]);//set g0 bit //set red bits spi.write(r1_array[7]);//set r7 bit spi.write(r1_array[6]); //set r6 bit spi.write(r1_array[5]); //set r5 bit spi.write(r1_array[4]); //set r4 bit spi.write(r1_array[3]); //set r3 bit spi.write(r1_array[2]); //set r2 bit spi.write(r1_array[1]); //set r1 bit spi.write(r1_array[0]); //set r0 bit //set blue bits spi.write(b1_array[7]); //set b7 bit spi.write(b1_array[6]); //set b6 bit spi.write(b1_array[5]); //set b5 bit spi.write(b1_array[4]); //set b4 bit spi.write(b1_array[3]); //set b3 bit spi.write(b1_array[2]); //set b2 bit spi.write(b1_array[1]); //set b1 bit spi.write(b1_array[0]); //set b0 bit //LED1 //set green bits spi.write(g1_array[7]); //set g7 bit spi.write(g1_array[6]); //set g6 bit spi.write(g1_array[5]); //set g5 bit spi.write(g1_array[4]); //set g4 bit spi.write(g1_array[3]); //set g3 bit spi.write(g1_array[2]); //set g2 bit spi.write(g1_array[1]); //set g1 bit spi.write(g1_array[0]);//set g0 bit //set red bits spi.write(r1_array[7]);//set r7 bit spi.write(r1_array[6]); //set r6 bit spi.write(r1_array[5]); //set r5 bit spi.write(r1_array[4]); //set r4 bit spi.write(r1_array[3]); //set r3 bit spi.write(r1_array[2]); //set r2 bit spi.write(r1_array[1]); //set r1 bit spi.write(r1_array[0]); //set r0 bit //set blue bits spi.write(b1_array[7]); //set b7 bit spi.write(b1_array[6]); //set b6 bit spi.write(b1_array[5]); //set b5 bit spi.write(b1_array[4]); //set b4 bit spi.write(b1_array[3]); //set b3 bit spi.write(b1_array[2]); //set b2 bit spi.write(b1_array[1]); //set b1 bit spi.write(b1_array[0]); //set b0 bit //LED2 //set green bits spi.write(g1_array[7]); //set g7 bit spi.write(g1_array[6]); //set g6 bit spi.write(g1_array[5]); //set g5 bit spi.write(g1_array[4]); //set g4 bit spi.write(g1_array[3]); //set g3 bit spi.write(g1_array[2]); //set g2 bit spi.write(g1_array[1]); //set g1 bit spi.write(g1_array[0]);//set g0 bit //set red bits spi.write(r1_array[7]);//set r7 bit spi.write(r1_array[6]); //set r6 bit spi.write(r1_array[5]); //set r5 bit spi.write(r1_array[4]); //set r4 bit spi.write(r1_array[3]); //set r3 bit spi.write(r1_array[2]); //set r2 bit spi.write(r1_array[1]); //set r1 bit spi.write(r1_array[0]); //set r0 bit //set blue bits spi.write(b1_array[7]); //set b7 bit spi.write(b1_array[6]); //set b6 bit spi.write(b1_array[5]); //set b5 bit spi.write(b1_array[4]); //set b4 bit spi.write(b1_array[3]); //set b3 bit spi.write(b1_array[2]); //set b2 bit spi.write(b1_array[1]); //set b1 bit spi.write(b1_array[0]); //set b0 bit //LED3 //set green bits spi.write(g1_array[7]); //set g7 bit spi.write(g1_array[6]); //set g6 bit spi.write(g1_array[5]); //set g5 bit spi.write(g1_array[4]); //set g4 bit spi.write(g1_array[3]); //set g3 bit spi.write(g1_array[2]); //set g2 bit spi.write(g1_array[1]); //set g1 bit spi.write(g1_array[0]);//set g0 bit //set red bits spi.write(r1_array[7]);//set r7 bit spi.write(r1_array[6]); //set r6 bit spi.write(r1_array[5]); //set r5 bit spi.write(r1_array[4]); //set r4 bit spi.write(r1_array[3]); //set r3 bit spi.write(r1_array[2]); //set r2 bit spi.write(r1_array[1]); //set r1 bit spi.write(r1_array[0]); //set r0 bit //set blue bits spi.write(b1_array[7]); //set b7 bit spi.write(b1_array[6]); //set b6 bit spi.write(b1_array[5]); //set b5 bit spi.write(b1_array[4]); //set b4 bit spi.write(b1_array[3]); //set b3 bit spi.write(b1_array[2]); //set b2 bit spi.write(b1_array[1]); //set b1 bit spi.write(b1_array[0]); //set b0 bit //LED4 //set green bits spi.write(g1_array[7]); //set g7 bit spi.write(g1_array[6]); //set g6 bit spi.write(g1_array[5]); //set g5 bit spi.write(g1_array[4]); //set g4 bit spi.write(g1_array[3]); //set g3 bit spi.write(g1_array[2]); //set g2 bit spi.write(g1_array[1]); //set g1 bit spi.write(g1_array[0]);//set g0 bit //set red bits spi.write(r1_array[7]);//set r7 bit spi.write(r1_array[6]); //set r6 bit spi.write(r1_array[5]); //set r5 bit spi.write(r1_array[4]); //set r4 bit spi.write(r1_array[3]); //set r3 bit spi.write(r1_array[2]); //set r2 bit spi.write(r1_array[1]); //set r1 bit spi.write(r1_array[0]); //set r0 bit //set blue bits spi.write(b1_array[7]); //set b7 bit spi.write(b1_array[6]); //set b6 bit spi.write(b1_array[5]); //set b5 bit spi.write(b1_array[4]); //set b4 bit spi.write(b1_array[3]); //set b3 bit spi.write(b1_array[2]); //set b2 bit spi.write(b1_array[1]); //set b1 bit spi.write(b1_array[0]); //set b0 bit //LED5 //set green bits spi.write(g1_array[7]); //set g7 bit spi.write(g1_array[6]); //set g6 bit spi.write(g1_array[5]); //set g5 bit spi.write(g1_array[4]); //set g4 bit spi.write(g1_array[3]); //set g3 bit spi.write(g1_array[2]); //set g2 bit spi.write(g1_array[1]); //set g1 bit spi.write(g1_array[0]);//set g0 bit //set red bits spi.write(r1_array[7]);//set r7 bit spi.write(r1_array[6]); //set r6 bit spi.write(r1_array[5]); //set r5 bit spi.write(r1_array[4]); //set r4 bit spi.write(r1_array[3]); //set r3 bit spi.write(r1_array[2]); //set r2 bit spi.write(r1_array[1]); //set r1 bit spi.write(r1_array[0]); //set r0 bit //set blue bits spi.write(b1_array[7]); //set b7 bit spi.write(b1_array[6]); //set b6 bit spi.write(b1_array[5]); //set b5 bit spi.write(b1_array[4]); //set b4 bit spi.write(b1_array[3]); //set b3 bit spi.write(b1_array[2]); //set b2 bit spi.write(b1_array[1]); //set b1 bit spi.write(b1_array[0]); //set b0 bit //LED6 //set green bits spi.write(g1_array[7]); //set g7 bit spi.write(g1_array[6]); //set g6 bit spi.write(g1_array[5]); //set g5 bit spi.write(g1_array[4]); //set g4 bit spi.write(g1_array[3]); //set g3 bit spi.write(g1_array[2]); //set g2 bit spi.write(g1_array[1]); //set g1 bit spi.write(g1_array[0]);//set g0 bit //set red bits spi.write(r1_array[7]);//set r7 bit spi.write(r1_array[6]); //set r6 bit spi.write(r1_array[5]); //set r5 bit spi.write(r1_array[4]); //set r4 bit spi.write(r1_array[3]); //set r3 bit spi.write(r1_array[2]); //set r2 bit spi.write(r1_array[1]); //set r1 bit spi.write(r1_array[0]); //set r0 bit //set blue bits spi.write(b1_array[7]); //set b7 bit spi.write(b1_array[6]); //set b6 bit spi.write(b1_array[5]); //set b5 bit spi.write(b1_array[4]); //set b4 bit spi.write(b1_array[3]); //set b3 bit spi.write(b1_array[2]); //set b2 bit spi.write(b1_array[1]); //set b1 bit spi.write(b1_array[0]); //set b0 bit //LED7 //set green bits spi.write(g1_array[7]); //set g7 bit spi.write(g1_array[6]); //set g6 bit spi.write(g1_array[5]); //set g5 bit spi.write(g1_array[4]); //set g4 bit spi.write(g1_array[3]); //set g3 bit spi.write(g1_array[2]); //set g2 bit spi.write(g1_array[1]); //set g1 bit spi.write(g1_array[0]);//set g0 bit //set red bits spi.write(r1_array[7]);//set r7 bit spi.write(r1_array[6]); //set r6 bit spi.write(r1_array[5]); //set r5 bit spi.write(r1_array[4]); //set r4 bit spi.write(r1_array[3]); //set r3 bit spi.write(r1_array[2]); //set r2 bit spi.write(r1_array[1]); //set r1 bit spi.write(r1_array[0]); //set r0 bit //set blue bits spi.write(b1_array[7]); //set b7 bit spi.write(b1_array[6]); //set b6 bit spi.write(b1_array[5]); //set b5 bit spi.write(b1_array[4]); //set b4 bit spi.write(b1_array[3]); //set b3 bit spi.write(b1_array[2]); //set b2 bit spi.write(b1_array[1]); //set b1 bit spi.write(b1_array[0]); //set b0 bit //room3 //LED0 //set green bits spi.write(g2_array[7]); //set g7 bit spi.write(g2_array[6]); //set g6 bit spi.write(g2_array[5]); //set g5 bit spi.write(g2_array[4]); //set g4 bit spi.write(g2_array[3]); //set g3 bit spi.write(g2_array[2]); //set g2 bit spi.write(g2_array[1]); //set g1 bit spi.write(g2_array[0]);//set g0 bit //set red bits spi.write(r2_array[7]);//set r7 bit spi.write(r2_array[6]); //set r6 bit spi.write(r2_array[5]); //set r5 bit spi.write(r2_array[4]); //set r4 bit spi.write(r2_array[3]); //set r3 bit spi.write(r2_array[2]); //set r2 bit spi.write(r2_array[1]); //set r1 bit spi.write(r2_array[0]); //set r0 bit //set blue bits spi.write(b2_array[7]); //set b7 bit spi.write(b2_array[6]); //set b6 bit spi.write(b2_array[5]); //set b5 bit spi.write(b2_array[4]); //set b4 bit spi.write(b2_array[3]); //set b3 bit spi.write(b2_array[2]); //set b2 bit spi.write(b2_array[1]); //set b1 bit spi.write(b2_array[0]); //set b0 bit //LED1 //set green bits spi.write(g2_array[7]); //set g7 bit spi.write(g2_array[6]); //set g6 bit spi.write(g2_array[5]); //set g5 bit spi.write(g2_array[4]); //set g4 bit spi.write(g2_array[3]); //set g3 bit spi.write(g2_array[2]); //set g2 bit spi.write(g2_array[1]); //set g1 bit spi.write(g2_array[0]);//set g0 bit //set red bits spi.write(r2_array[7]);//set r7 bit spi.write(r2_array[6]); //set r6 bit spi.write(r2_array[5]); //set r5 bit spi.write(r2_array[4]); //set r4 bit spi.write(r2_array[3]); //set r3 bit spi.write(r2_array[2]); //set r2 bit spi.write(r2_array[1]); //set r1 bit spi.write(r2_array[0]); //set r0 bit //set blue bits spi.write(b2_array[7]); //set b7 bit spi.write(b2_array[6]); //set b6 bit spi.write(b2_array[5]); //set b5 bit spi.write(b2_array[4]); //set b4 bit spi.write(b2_array[3]); //set b3 bit spi.write(b2_array[2]); //set b2 bit spi.write(b2_array[1]); //set b1 bit spi.write(b2_array[0]); //set b0 bit //LED2 //set green bits spi.write(g2_array[7]); //set g7 bit spi.write(g2_array[6]); //set g6 bit spi.write(g2_array[5]); //set g5 bit spi.write(g2_array[4]); //set g4 bit spi.write(g2_array[3]); //set g3 bit spi.write(g2_array[2]); //set g2 bit spi.write(g2_array[1]); //set g1 bit spi.write(g2_array[0]);//set g0 bit //set red bits spi.write(r2_array[7]);//set r7 bit spi.write(r2_array[6]); //set r6 bit spi.write(r2_array[5]); //set r5 bit spi.write(r2_array[4]); //set r4 bit spi.write(r2_array[3]); //set r3 bit spi.write(r2_array[2]); //set r2 bit spi.write(r2_array[1]); //set r1 bit spi.write(r2_array[0]); //set r0 bit //set blue bits spi.write(b2_array[7]); //set b7 bit spi.write(b2_array[6]); //set b6 bit spi.write(b2_array[5]); //set b5 bit spi.write(b2_array[4]); //set b4 bit spi.write(b2_array[3]); //set b3 bit spi.write(b2_array[2]); //set b2 bit spi.write(b2_array[1]); //set b1 bit spi.write(b2_array[0]); //set b0 bit //LED3 //set green bits spi.write(g2_array[7]); //set g7 bit spi.write(g2_array[6]); //set g6 bit spi.write(g2_array[5]); //set g5 bit spi.write(g2_array[4]); //set g4 bit spi.write(g2_array[3]); //set g3 bit spi.write(g2_array[2]); //set g2 bit spi.write(g2_array[1]); //set g1 bit spi.write(g2_array[0]);//set g0 bit //set red bits spi.write(r2_array[7]);//set r7 bit spi.write(r2_array[6]); //set r6 bit spi.write(r2_array[5]); //set r5 bit spi.write(r2_array[4]); //set r4 bit spi.write(r2_array[3]); //set r3 bit spi.write(r2_array[2]); //set r2 bit spi.write(r2_array[1]); //set r1 bit spi.write(r2_array[0]); //set r0 bit //set blue bits spi.write(b2_array[7]); //set b7 bit spi.write(b2_array[6]); //set b6 bit spi.write(b2_array[5]); //set b5 bit spi.write(b2_array[4]); //set b4 bit spi.write(b2_array[3]); //set b3 bit spi.write(b2_array[2]); //set b2 bit spi.write(b2_array[1]); //set b1 bit spi.write(b2_array[0]); //set b0 bit //LED4 //set green bits spi.write(g2_array[7]); //set g7 bit spi.write(g2_array[6]); //set g6 bit spi.write(g2_array[5]); //set g5 bit spi.write(g2_array[4]); //set g4 bit spi.write(g2_array[3]); //set g3 bit spi.write(g2_array[2]); //set g2 bit spi.write(g2_array[1]); //set g1 bit spi.write(g2_array[0]);//set g0 bit //set red bits spi.write(r2_array[7]);//set r7 bit spi.write(r2_array[6]); //set r6 bit spi.write(r2_array[5]); //set r5 bit spi.write(r2_array[4]); //set r4 bit spi.write(r2_array[3]); //set r3 bit spi.write(r2_array[2]); //set r2 bit spi.write(r2_array[1]); //set r1 bit spi.write(r2_array[0]); //set r0 bit //set blue bits spi.write(b2_array[7]); //set b7 bit spi.write(b2_array[6]); //set b6 bit spi.write(b2_array[5]); //set b5 bit spi.write(b2_array[4]); //set b4 bit spi.write(b2_array[3]); //set b3 bit spi.write(b2_array[2]); //set b2 bit spi.write(b2_array[1]); //set b1 bit spi.write(b2_array[0]); //set b0 bit //LED5 //set green bits spi.write(g2_array[7]); //set g7 bit spi.write(g2_array[6]); //set g6 bit spi.write(g2_array[5]); //set g5 bit spi.write(g2_array[4]); //set g4 bit spi.write(g2_array[3]); //set g3 bit spi.write(g2_array[2]); //set g2 bit spi.write(g2_array[1]); //set g1 bit spi.write(g2_array[0]);//set g0 bit //set red bits spi.write(r2_array[7]);//set r7 bit spi.write(r2_array[6]); //set r6 bit spi.write(r2_array[5]); //set r5 bit spi.write(r2_array[4]); //set r4 bit spi.write(r2_array[3]); //set r3 bit spi.write(r2_array[2]); //set r2 bit spi.write(r2_array[1]); //set r1 bit spi.write(r2_array[0]); //set r0 bit //set blue bits spi.write(b2_array[7]); //set b7 bit spi.write(b2_array[6]); //set b6 bit spi.write(b2_array[5]); //set b5 bit spi.write(b2_array[4]); //set b4 bit spi.write(b2_array[3]); //set b3 bit spi.write(b2_array[2]); //set b2 bit spi.write(b2_array[1]); //set b1 bit spi.write(b2_array[0]); //set b0 bit //LED6 //set green bits spi.write(g2_array[7]); //set g7 bit spi.write(g2_array[6]); //set g6 bit spi.write(g2_array[5]); //set g5 bit spi.write(g2_array[4]); //set g4 bit spi.write(g2_array[3]); //set g3 bit spi.write(g2_array[2]); //set g2 bit spi.write(g2_array[1]); //set g1 bit spi.write(g2_array[0]);//set g0 bit //set red bits spi.write(r2_array[7]);//set r7 bit spi.write(r2_array[6]); //set r6 bit spi.write(r2_array[5]); //set r5 bit spi.write(r2_array[4]); //set r4 bit spi.write(r2_array[3]); //set r3 bit spi.write(r2_array[2]); //set r2 bit spi.write(r2_array[1]); //set r1 bit spi.write(r2_array[0]); //set r0 bit //set blue bits spi.write(b2_array[7]); //set b7 bit spi.write(b2_array[6]); //set b6 bit spi.write(b2_array[5]); //set b5 bit spi.write(b2_array[4]); //set b4 bit spi.write(b2_array[3]); //set b3 bit spi.write(b2_array[2]); //set b2 bit spi.write(b2_array[1]); //set b1 bit spi.write(b2_array[0]); //set b0 bit //LED7 //set green bits spi.write(g2_array[7]); //set g7 bit spi.write(g2_array[6]); //set g6 bit spi.write(g2_array[5]); //set g5 bit spi.write(g2_array[4]); //set g4 bit spi.write(g2_array[3]); //set g3 bit spi.write(g2_array[2]); //set g2 bit spi.write(g2_array[1]); //set g1 bit spi.write(g2_array[0]);//set g0 bit //set red bits spi.write(r2_array[7]);//set r7 bit spi.write(r2_array[6]); //set r6 bit spi.write(r2_array[5]); //set r5 bit spi.write(r2_array[4]); //set r4 bit spi.write(r2_array[3]); //set r3 bit spi.write(r2_array[2]); //set r2 bit spi.write(r2_array[1]); //set r1 bit spi.write(r2_array[0]); //set r0 bit //set blue bits spi.write(b2_array[7]); //set b7 bit spi.write(b2_array[6]); //set b6 bit spi.write(b2_array[5]); //set b5 bit spi.write(b2_array[4]); //set b4 bit spi.write(b2_array[3]); //set b3 bit spi.write(b2_array[2]); //set b2 bit spi.write(b2_array[1]); //set b1 bit spi.write(b2_array[0]); //set b0 bit //room 4 //LED0 //set green bits spi.write(g3_array[7]); //set g7 bit spi.write(g3_array[6]); //set g6 bit spi.write(g3_array[5]); //set g5 bit spi.write(g3_array[4]); //set g4 bit spi.write(g3_array[3]); //set g3 bit spi.write(g3_array[2]); //set g2 bit spi.write(g3_array[1]); //set g1 bit spi.write(g3_array[0]);//set g0 bit //set red bits spi.write(r3_array[7]);//set r7 bit spi.write(r3_array[6]); //set r6 bit spi.write(r3_array[5]); //set r5 bit spi.write(r3_array[4]); //set r4 bit spi.write(r3_array[3]); //set r3 bit spi.write(r3_array[2]); //set r2 bit spi.write(r3_array[1]); //set r1 bit spi.write(r3_array[0]); //set r0 bit //set blue bits spi.write(b3_array[7]); //set b7 bit spi.write(b3_array[6]); //set b6 bit spi.write(b3_array[5]); //set b5 bit spi.write(b3_array[4]); //set b4 bit spi.write(b3_array[3]); //set b3 bit spi.write(b3_array[2]); //set b2 bit spi.write(b3_array[1]); //set b1 bit spi.write(b3_array[0]); //set b0 bit //LED1 //set green bits spi.write(g3_array[7]); //set g7 bit spi.write(g3_array[6]); //set g6 bit spi.write(g3_array[5]); //set g5 bit spi.write(g3_array[4]); //set g4 bit spi.write(g3_array[3]); //set g3 bit spi.write(g3_array[2]); //set g2 bit spi.write(g3_array[1]); //set g1 bit spi.write(g3_array[0]);//set g0 bit //set red bits spi.write(r3_array[7]);//set r7 bit spi.write(r3_array[6]); //set r6 bit spi.write(r3_array[5]); //set r5 bit spi.write(r3_array[4]); //set r4 bit spi.write(r3_array[3]); //set r3 bit spi.write(r3_array[2]); //set r2 bit spi.write(r3_array[1]); //set r1 bit spi.write(r3_array[0]); //set r0 bit //set blue bits spi.write(b3_array[7]); //set b7 bit spi.write(b3_array[6]); //set b6 bit spi.write(b3_array[5]); //set b5 bit spi.write(b3_array[4]); //set b4 bit spi.write(b3_array[3]); //set b3 bit spi.write(b3_array[2]); //set b2 bit spi.write(b3_array[1]); //set b1 bit spi.write(b3_array[0]); //set b0 bit //LED2 //set green bits spi.write(g3_array[7]); //set g7 bit spi.write(g3_array[6]); //set g6 bit spi.write(g3_array[5]); //set g5 bit spi.write(g3_array[4]); //set g4 bit spi.write(g3_array[3]); //set g3 bit spi.write(g3_array[2]); //set g2 bit spi.write(g3_array[1]); //set g1 bit spi.write(g3_array[0]);//set g0 bit //set red bits spi.write(r3_array[7]);//set r7 bit spi.write(r3_array[6]); //set r6 bit spi.write(r3_array[5]); //set r5 bit spi.write(r3_array[4]); //set r4 bit spi.write(r3_array[3]); //set r3 bit spi.write(r3_array[2]); //set r2 bit spi.write(r3_array[1]); //set r1 bit spi.write(r3_array[0]); //set r0 bit //set blue bits spi.write(b3_array[7]); //set b7 bit spi.write(b3_array[6]); //set b6 bit spi.write(b3_array[5]); //set b5 bit spi.write(b3_array[4]); //set b4 bit spi.write(b3_array[3]); //set b3 bit spi.write(b3_array[2]); //set b2 bit spi.write(b3_array[1]); //set b1 bit spi.write(b3_array[0]); //set b0 bit //LED3 //set green bits spi.write(g3_array[7]); //set g7 bit spi.write(g3_array[6]); //set g6 bit spi.write(g3_array[5]); //set g5 bit spi.write(g3_array[4]); //set g4 bit spi.write(g3_array[3]); //set g3 bit spi.write(g3_array[2]); //set g2 bit spi.write(g3_array[1]); //set g1 bit spi.write(g3_array[0]);//set g0 bit //set red bits spi.write(r3_array[7]);//set r7 bit spi.write(r3_array[6]); //set r6 bit spi.write(r3_array[5]); //set r5 bit spi.write(r3_array[4]); //set r4 bit spi.write(r3_array[3]); //set r3 bit spi.write(r3_array[2]); //set r2 bit spi.write(r3_array[1]); //set r1 bit spi.write(r3_array[0]); //set r0 bit //set blue bits spi.write(b3_array[7]); //set b7 bit spi.write(b3_array[6]); //set b6 bit spi.write(b3_array[5]); //set b5 bit spi.write(b3_array[4]); //set b4 bit spi.write(b3_array[3]); //set b3 bit spi.write(b3_array[2]); //set b2 bit spi.write(b3_array[1]); //set b1 bit spi.write(b3_array[0]); //set b0 bit //LED4 //set green bits spi.write(g3_array[7]); //set g7 bit spi.write(g3_array[6]); //set g6 bit spi.write(g3_array[5]); //set g5 bit spi.write(g3_array[4]); //set g4 bit spi.write(g3_array[3]); //set g3 bit spi.write(g3_array[2]); //set g2 bit spi.write(g3_array[1]); //set g1 bit spi.write(g3_array[0]);//set g0 bit //set red bits spi.write(r3_array[7]);//set r7 bit spi.write(r3_array[6]); //set r6 bit spi.write(r3_array[5]); //set r5 bit spi.write(r3_array[4]); //set r4 bit spi.write(r3_array[3]); //set r3 bit spi.write(r3_array[2]); //set r2 bit spi.write(r3_array[1]); //set r1 bit spi.write(r3_array[0]); //set r0 bit //set blue bits spi.write(b3_array[7]); //set b7 bit spi.write(b3_array[6]); //set b6 bit spi.write(b3_array[5]); //set b5 bit spi.write(b3_array[4]); //set b4 bit spi.write(b3_array[3]); //set b3 bit spi.write(b3_array[2]); //set b2 bit spi.write(b3_array[1]); //set b1 bit spi.write(b3_array[0]); //set b0 bit //LED5 //set green bits spi.write(g3_array[7]); //set g7 bit spi.write(g3_array[6]); //set g6 bit spi.write(g3_array[5]); //set g5 bit spi.write(g3_array[4]); //set g4 bit spi.write(g3_array[3]); //set g3 bit spi.write(g3_array[2]); //set g2 bit spi.write(g3_array[1]); //set g1 bit spi.write(g3_array[0]);//set g0 bit //set red bits spi.write(r3_array[7]);//set r7 bit spi.write(r3_array[6]); //set r6 bit spi.write(r3_array[5]); //set r5 bit spi.write(r3_array[4]); //set r4 bit spi.write(r3_array[3]); //set r3 bit spi.write(r3_array[2]); //set r2 bit spi.write(r3_array[1]); //set r1 bit spi.write(r3_array[0]); //set r0 bit //set blue bits spi.write(b3_array[7]); //set b7 bit spi.write(b3_array[6]); //set b6 bit spi.write(b3_array[5]); //set b5 bit spi.write(b3_array[4]); //set b4 bit spi.write(b3_array[3]); //set b3 bit spi.write(b3_array[2]); //set b2 bit spi.write(b3_array[1]); //set b1 bit spi.write(b3_array[0]); //set b0 bit //LED6 //set green bits spi.write(g3_array[7]); //set g7 bit spi.write(g3_array[6]); //set g6 bit spi.write(g3_array[5]); //set g5 bit spi.write(g3_array[4]); //set g4 bit spi.write(g3_array[3]); //set g3 bit spi.write(g3_array[2]); //set g2 bit spi.write(g3_array[1]); //set g1 bit spi.write(g3_array[0]);//set g0 bit //set red bits spi.write(r3_array[7]);//set r7 bit spi.write(r3_array[6]); //set r6 bit spi.write(r3_array[5]); //set r5 bit spi.write(r3_array[4]); //set r4 bit spi.write(r3_array[3]); //set r3 bit spi.write(r3_array[2]); //set r2 bit spi.write(r3_array[1]); //set r1 bit spi.write(r3_array[0]); //set r0 bit //set blue bits spi.write(b3_array[7]); //set b7 bit spi.write(b3_array[6]); //set b6 bit spi.write(b3_array[5]); //set b5 bit spi.write(b3_array[4]); //set b4 bit spi.write(b3_array[3]); //set b3 bit spi.write(b3_array[2]); //set b2 bit spi.write(b3_array[1]); //set b1 bit spi.write(b3_array[0]); //set b0 bit //LED7 //set green bits spi.write(g3_array[7]); //set g7 bit spi.write(g3_array[6]); //set g6 bit spi.write(g3_array[5]); //set g5 bit spi.write(g3_array[4]); //set g4 bit spi.write(g3_array[3]); //set g3 bit spi.write(g3_array[2]); //set g2 bit spi.write(g3_array[1]); //set g1 bit spi.write(g3_array[0]);//set g0 bit //set red bits spi.write(r3_array[7]);//set r7 bit spi.write(r3_array[6]); //set r6 bit spi.write(r3_array[5]); //set r5 bit spi.write(r3_array[4]); //set r4 bit spi.write(r3_array[3]); //set r3 bit spi.write(r3_array[2]); //set r2 bit spi.write(r3_array[1]); //set r1 bit spi.write(r3_array[0]); //set r0 bit //set blue bits spi.write(b3_array[7]); //set b7 bit spi.write(b3_array[6]); //set b6 bit spi.write(b3_array[5]); //set b5 bit spi.write(b3_array[4]); //set b4 bit spi.write(b3_array[3]); //set b3 bit spi.write(b3_array[2]); //set b2 bit spi.write(b3_array[1]); //set b1 bit spi.write(b3_array[0]); //set b0 bit //wait for latch wait_us(60); } void setRGBAll(int colours[4][8][3]){ //translate int values to array of 0xF00 (0) and 0xFF0 (1) binary //room1 int r00_array[8]; //LED0 int g00_array[8]; int b00_array[8]; memcpy(r00_array, decimalToBinary(colours[0][0][0]), sizeof(r00_array)); memcpy(g00_array, decimalToBinary(colours[0][0][1]), sizeof(g00_array)); memcpy(b00_array, decimalToBinary(colours[0][0][2]), sizeof(b00_array)); int r01_array[8]; //LED1 int g01_array[8]; int b01_array[8]; memcpy(r01_array, decimalToBinary(colours[0][1][0]), sizeof(r01_array)); memcpy(g01_array, decimalToBinary(colours[0][1][1]), sizeof(g01_array)); memcpy(b01_array, decimalToBinary(colours[0][1][2]), sizeof(b01_array)); int r02_array[8]; //LED2 int g02_array[8]; int b02_array[8]; memcpy(r02_array, decimalToBinary(colours[0][2][0]), sizeof(r02_array)); memcpy(g02_array, decimalToBinary(colours[0][2][1]), sizeof(g02_array)); memcpy(b02_array, decimalToBinary(colours[0][2][2]), sizeof(b02_array)); int r03_array[8]; //LED3 int g03_array[8]; int b03_array[8]; memcpy(r03_array, decimalToBinary(colours[0][3][0]), sizeof(r03_array)); memcpy(g03_array, decimalToBinary(colours[0][3][1]), sizeof(g03_array)); memcpy(b03_array, decimalToBinary(colours[0][3][2]), sizeof(b03_array)); int r04_array[8]; //LED4 int g04_array[8]; int b04_array[8]; memcpy(r04_array, decimalToBinary(colours[0][4][0]), sizeof(r04_array)); memcpy(g04_array, decimalToBinary(colours[0][4][1]), sizeof(g04_array)); memcpy(b04_array, decimalToBinary(colours[0][4][2]), sizeof(b04_array)); int r05_array[8]; //LED5 int g05_array[8]; int b05_array[8]; memcpy(r05_array, decimalToBinary(colours[0][5][0]), sizeof(r05_array)); memcpy(g05_array, decimalToBinary(colours[0][5][1]), sizeof(g05_array)); memcpy(b05_array, decimalToBinary(colours[0][5][2]), sizeof(b05_array)); int r06_array[8]; //LED6 int g06_array[8]; int b06_array[8]; memcpy(r06_array, decimalToBinary(colours[0][6][0]), sizeof(r06_array)); memcpy(g06_array, decimalToBinary(colours[0][6][1]), sizeof(g06_array)); memcpy(b06_array, decimalToBinary(colours[0][6][2]), sizeof(b06_array)); int r07_array[8]; //LED7 int g07_array[8]; int b07_array[8]; memcpy(r07_array, decimalToBinary(colours[0][7][0]), sizeof(r07_array)); memcpy(g07_array, decimalToBinary(colours[0][7][1]), sizeof(g07_array)); memcpy(b07_array, decimalToBinary(colours[0][7][2]), sizeof(b07_array)); //room2 int r10_array[8]; //LED0 int g10_array[8]; int b10_array[8]; memcpy(r10_array, decimalToBinary(colours[1][0][0]), sizeof(r10_array)); memcpy(g10_array, decimalToBinary(colours[1][0][1]), sizeof(g10_array)); memcpy(b10_array, decimalToBinary(colours[1][0][2]), sizeof(b10_array)); int r11_array[8]; //LED1 int g11_array[8]; int b11_array[8]; memcpy(r11_array, decimalToBinary(colours[1][1][0]), sizeof(r11_array)); memcpy(g11_array, decimalToBinary(colours[1][1][1]), sizeof(g11_array)); memcpy(b11_array, decimalToBinary(colours[1][1][2]), sizeof(b11_array)); int r12_array[8]; //LED2 int g12_array[8]; int b12_array[8]; memcpy(r12_array, decimalToBinary(colours[1][2][0]), sizeof(r12_array)); memcpy(g12_array, decimalToBinary(colours[1][2][1]), sizeof(g12_array)); memcpy(b12_array, decimalToBinary(colours[1][2][2]), sizeof(b12_array)); int r13_array[8]; //LED3 int g13_array[8]; int b13_array[8]; memcpy(r13_array, decimalToBinary(colours[1][3][0]), sizeof(r13_array)); memcpy(g13_array, decimalToBinary(colours[1][3][1]), sizeof(g13_array)); memcpy(b13_array, decimalToBinary(colours[1][3][2]), sizeof(b13_array)); int r14_array[8]; //LED4 int g14_array[8]; int b14_array[8]; memcpy(r14_array, decimalToBinary(colours[1][4][0]), sizeof(r14_array)); memcpy(g14_array, decimalToBinary(colours[1][4][1]), sizeof(g14_array)); memcpy(b14_array, decimalToBinary(colours[1][4][2]), sizeof(b14_array)); int r15_array[8]; //LED5 int g15_array[8]; int b15_array[8]; memcpy(r15_array, decimalToBinary(colours[1][5][0]), sizeof(r15_array)); memcpy(g15_array, decimalToBinary(colours[1][5][1]), sizeof(g15_array)); memcpy(b15_array, decimalToBinary(colours[1][5][2]), sizeof(b15_array)); int r16_array[8]; //LED6 int g16_array[8]; int b16_array[8]; memcpy(r16_array, decimalToBinary(colours[1][6][0]), sizeof(r16_array)); memcpy(g16_array, decimalToBinary(colours[1][6][1]), sizeof(g16_array)); memcpy(b16_array, decimalToBinary(colours[1][6][2]), sizeof(b16_array)); int r17_array[8]; //LED7 int g17_array[8]; int b17_array[8]; memcpy(r17_array, decimalToBinary(colours[1][7][0]), sizeof(r17_array)); memcpy(g17_array, decimalToBinary(colours[1][7][1]), sizeof(g17_array)); memcpy(b17_array, decimalToBinary(colours[1][7][2]), sizeof(b17_array)); //room3 int r20_array[8]; //LED0 int g20_array[8]; int b20_array[8]; memcpy(r20_array, decimalToBinary(colours[2][0][0]), sizeof(r20_array)); memcpy(g20_array, decimalToBinary(colours[2][0][1]), sizeof(g20_array)); memcpy(b20_array, decimalToBinary(colours[2][0][2]), sizeof(b20_array)); int r21_array[8]; //LED1 int g21_array[8]; int b21_array[8]; memcpy(r21_array, decimalToBinary(colours[2][1][0]), sizeof(r21_array)); memcpy(g21_array, decimalToBinary(colours[2][1][1]), sizeof(g21_array)); memcpy(b21_array, decimalToBinary(colours[2][1][2]), sizeof(b21_array)); int r22_array[8]; //LED2 int g22_array[8]; int b22_array[8]; memcpy(r22_array, decimalToBinary(colours[2][2][0]), sizeof(r22_array)); memcpy(g22_array, decimalToBinary(colours[2][2][1]), sizeof(g22_array)); memcpy(b22_array, decimalToBinary(colours[2][2][2]), sizeof(b22_array)); int r23_array[8]; //LED3 int g23_array[8]; int b23_array[8]; memcpy(r23_array, decimalToBinary(colours[2][3][0]), sizeof(r23_array)); memcpy(g23_array, decimalToBinary(colours[2][3][1]), sizeof(g23_array)); memcpy(b23_array, decimalToBinary(colours[2][3][2]), sizeof(b23_array)); int r24_array[8]; //LED4 int g24_array[8]; int b24_array[8]; memcpy(r24_array, decimalToBinary(colours[2][4][0]), sizeof(r24_array)); memcpy(g24_array, decimalToBinary(colours[2][4][1]), sizeof(g24_array)); memcpy(b24_array, decimalToBinary(colours[2][4][2]), sizeof(b24_array)); int r25_array[8]; //LED5 int g25_array[8]; int b25_array[8]; memcpy(r25_array, decimalToBinary(colours[2][5][0]), sizeof(r25_array)); memcpy(g25_array, decimalToBinary(colours[2][5][1]), sizeof(g25_array)); memcpy(b25_array, decimalToBinary(colours[2][5][2]), sizeof(b25_array)); int r26_array[8]; //LED6 int g26_array[8]; int b26_array[8]; memcpy(r26_array, decimalToBinary(colours[2][6][0]), sizeof(r26_array)); memcpy(g26_array, decimalToBinary(colours[2][6][1]), sizeof(g26_array)); memcpy(b26_array, decimalToBinary(colours[2][6][2]), sizeof(b26_array)); int r27_array[8]; //LED7 int g27_array[8]; int b27_array[8]; memcpy(r27_array, decimalToBinary(colours[2][7][0]), sizeof(r27_array)); memcpy(g27_array, decimalToBinary(colours[2][7][1]), sizeof(g27_array)); memcpy(b27_array, decimalToBinary(colours[2][7][2]), sizeof(b27_array)); //room4 int r30_array[8]; //LED0 int g30_array[8]; int b30_array[8]; memcpy(r30_array, decimalToBinary(colours[3][0][0]), sizeof(r30_array)); memcpy(g30_array, decimalToBinary(colours[3][0][1]), sizeof(g30_array)); memcpy(b30_array, decimalToBinary(colours[3][0][2]), sizeof(b30_array)); int r31_array[8]; //LED1 int g31_array[8]; int b31_array[8]; memcpy(r31_array, decimalToBinary(colours[3][1][0]), sizeof(r31_array)); memcpy(g31_array, decimalToBinary(colours[3][1][1]), sizeof(g31_array)); memcpy(b31_array, decimalToBinary(colours[3][1][2]), sizeof(b31_array)); int r32_array[8]; //LED2 int g32_array[8]; int b32_array[8]; memcpy(r32_array, decimalToBinary(colours[3][2][0]), sizeof(r32_array)); memcpy(g32_array, decimalToBinary(colours[3][2][1]), sizeof(g32_array)); memcpy(b32_array, decimalToBinary(colours[3][2][2]), sizeof(b32_array)); int r33_array[8]; //LED3 int g33_array[8]; int b33_array[8]; memcpy(r33_array, decimalToBinary(colours[3][3][0]), sizeof(r33_array)); memcpy(g33_array, decimalToBinary(colours[3][3][1]), sizeof(g33_array)); memcpy(b33_array, decimalToBinary(colours[3][3][2]), sizeof(b33_array)); int r34_array[8]; //LED4 int g34_array[8]; int b34_array[8]; memcpy(r34_array, decimalToBinary(colours[3][4][0]), sizeof(r34_array)); memcpy(g34_array, decimalToBinary(colours[3][4][1]), sizeof(g34_array)); memcpy(b34_array, decimalToBinary(colours[3][4][2]), sizeof(b34_array)); int r35_array[8]; //LED5 int g35_array[8]; int b35_array[8]; memcpy(r35_array, decimalToBinary(colours[3][5][0]), sizeof(r35_array)); memcpy(g35_array, decimalToBinary(colours[3][5][1]), sizeof(g35_array)); memcpy(b35_array, decimalToBinary(colours[3][5][2]), sizeof(b35_array)); int r36_array[8]; //LED6 int g36_array[8]; int b36_array[8]; memcpy(r36_array, decimalToBinary(colours[3][6][0]), sizeof(r36_array)); memcpy(g36_array, decimalToBinary(colours[3][6][1]), sizeof(g36_array)); memcpy(b36_array, decimalToBinary(colours[3][6][2]), sizeof(b36_array)); int r37_array[8]; //LED7 int g37_array[8]; int b37_array[8]; memcpy(r37_array, decimalToBinary(colours[3][7][0]), sizeof(r37_array)); memcpy(g37_array, decimalToBinary(colours[3][7][1]), sizeof(g37_array)); memcpy(b37_array, decimalToBinary(colours[3][7][2]), sizeof(b37_array)); //send commands to LED Driver //initialize SPI spi_init(); //room1 //LED0 //set green bits spi.write(g00_array[7]); //set g7 bit spi.write(g00_array[6]); //set g6 bit spi.write(g00_array[5]); //set g5 bit spi.write(g00_array[4]); //set g4 bit spi.write(g00_array[3]); //set g3 bit spi.write(g00_array[2]); //set g2 bit spi.write(g00_array[1]); //set g1 bit spi.write(g00_array[0]);//set g0 bit //set red bits spi.write(r00_array[7]);//set r7 bit spi.write(r00_array[6]); //set r6 bit spi.write(r00_array[5]); //set r5 bit spi.write(r00_array[4]); //set r4 bit spi.write(r00_array[3]); //set r3 bit spi.write(r00_array[2]); //set r2 bit spi.write(r00_array[1]); //set r1 bit spi.write(r00_array[0]); //set r0 bit //set blue bits spi.write(b00_array[7]); //set b7 bit spi.write(b00_array[6]); //set b6 bit spi.write(b00_array[5]); //set b5 bit spi.write(b00_array[4]); //set b4 bit spi.write(b00_array[3]); //set b3 bit spi.write(b00_array[2]); //set b2 bit spi.write(b00_array[1]); //set b1 bit spi.write(b00_array[0]); //set b0 bit //LED1 //set green bits spi.write(g01_array[7]); //set g7 bit spi.write(g01_array[6]); //set g6 bit spi.write(g01_array[5]); //set g5 bit spi.write(g01_array[4]); //set g4 bit spi.write(g01_array[3]); //set g3 bit spi.write(g01_array[2]); //set g2 bit spi.write(g01_array[1]); //set g1 bit spi.write(g01_array[0]);//set g0 bit //set red bits spi.write(r01_array[7]);//set r7 bit spi.write(r01_array[6]); //set r6 bit spi.write(r01_array[5]); //set r5 bit spi.write(r01_array[4]); //set r4 bit spi.write(r01_array[3]); //set r3 bit spi.write(r01_array[2]); //set r2 bit spi.write(r01_array[1]); //set r1 bit spi.write(r01_array[0]); //set r0 bit //set blue bits spi.write(b01_array[7]); //set b7 bit spi.write(b01_array[6]); //set b6 bit spi.write(b01_array[5]); //set b5 bit spi.write(b01_array[4]); //set b4 bit spi.write(b01_array[3]); //set b3 bit spi.write(b01_array[2]); //set b2 bit spi.write(b01_array[1]); //set b1 bit spi.write(b01_array[0]); //set b0 bit //LED2 //set green bits spi.write(g02_array[7]); //set g7 bit spi.write(g02_array[6]); //set g6 bit spi.write(g02_array[5]); //set g5 bit spi.write(g02_array[4]); //set g4 bit spi.write(g02_array[3]); //set g3 bit spi.write(g02_array[2]); //set g2 bit spi.write(g02_array[1]); //set g1 bit spi.write(g02_array[0]);//set g0 bit //set red bits spi.write(r02_array[7]);//set r7 bit spi.write(r02_array[6]); //set r6 bit spi.write(r02_array[5]); //set r5 bit spi.write(r02_array[4]); //set r4 bit spi.write(r02_array[3]); //set r3 bit spi.write(r02_array[2]); //set r2 bit spi.write(r02_array[1]); //set r1 bit spi.write(r02_array[0]); //set r0 bit //set blue bits spi.write(b02_array[7]); //set b7 bit spi.write(b02_array[6]); //set b6 bit spi.write(b02_array[5]); //set b5 bit spi.write(b02_array[4]); //set b4 bit spi.write(b02_array[3]); //set b3 bit spi.write(b02_array[2]); //set b2 bit spi.write(b02_array[1]); //set b1 bit spi.write(b02_array[0]); //set b0 bit //LED3 //set green bits spi.write(g03_array[7]); //set g7 bit spi.write(g03_array[6]); //set g6 bit spi.write(g03_array[5]); //set g5 bit spi.write(g03_array[4]); //set g4 bit spi.write(g03_array[3]); //set g3 bit spi.write(g03_array[2]); //set g2 bit spi.write(g03_array[1]); //set g1 bit spi.write(g03_array[0]);//set g0 bit //set red bits spi.write(r03_array[7]);//set r7 bit spi.write(r03_array[6]); //set r6 bit spi.write(r03_array[5]); //set r5 bit spi.write(r03_array[4]); //set r4 bit spi.write(r03_array[3]); //set r3 bit spi.write(r03_array[2]); //set r2 bit spi.write(r03_array[1]); //set r1 bit spi.write(r03_array[0]); //set r0 bit //set blue bits spi.write(b03_array[7]); //set b7 bit spi.write(b03_array[6]); //set b6 bit spi.write(b03_array[5]); //set b5 bit spi.write(b03_array[4]); //set b4 bit spi.write(b03_array[3]); //set b3 bit spi.write(b03_array[2]); //set b2 bit spi.write(b03_array[1]); //set b1 bit spi.write(b03_array[0]); //set b0 bit //LED4 //set green bits spi.write(g04_array[7]); //set g7 bit spi.write(g04_array[6]); //set g6 bit spi.write(g04_array[5]); //set g5 bit spi.write(g04_array[4]); //set g4 bit spi.write(g04_array[3]); //set g3 bit spi.write(g04_array[2]); //set g2 bit spi.write(g04_array[1]); //set g1 bit spi.write(g04_array[0]);//set g0 bit //set red bits spi.write(r04_array[7]);//set r7 bit spi.write(r04_array[6]); //set r6 bit spi.write(r04_array[5]); //set r5 bit spi.write(r04_array[4]); //set r4 bit spi.write(r04_array[3]); //set r3 bit spi.write(r04_array[2]); //set r2 bit spi.write(r04_array[1]); //set r1 bit spi.write(r04_array[0]); //set r0 bit //set blue bits spi.write(b04_array[7]); //set b7 bit spi.write(b04_array[6]); //set b6 bit spi.write(b04_array[5]); //set b5 bit spi.write(b04_array[4]); //set b4 bit spi.write(b04_array[3]); //set b3 bit spi.write(b04_array[2]); //set b2 bit spi.write(b04_array[1]); //set b1 bit spi.write(b04_array[0]); //set b0 bit //LED5 //set green bits spi.write(g05_array[7]); //set g7 bit spi.write(g05_array[6]); //set g6 bit spi.write(g05_array[5]); //set g5 bit spi.write(g05_array[4]); //set g4 bit spi.write(g05_array[3]); //set g3 bit spi.write(g05_array[2]); //set g2 bit spi.write(g05_array[1]); //set g1 bit spi.write(g05_array[0]);//set g0 bit //set red bits spi.write(r05_array[7]);//set r7 bit spi.write(r05_array[6]); //set r6 bit spi.write(r05_array[5]); //set r5 bit spi.write(r05_array[4]); //set r4 bit spi.write(r05_array[3]); //set r3 bit spi.write(r05_array[2]); //set r2 bit spi.write(r05_array[1]); //set r1 bit spi.write(r05_array[0]); //set r0 bit //set blue bits spi.write(b05_array[7]); //set b7 bit spi.write(b05_array[6]); //set b6 bit spi.write(b05_array[5]); //set b5 bit spi.write(b05_array[4]); //set b4 bit spi.write(b05_array[3]); //set b3 bit spi.write(b05_array[2]); //set b2 bit spi.write(b05_array[1]); //set b1 bit spi.write(b05_array[0]); //set b0 bit //LED6 //set green bits spi.write(g06_array[7]); //set g7 bit spi.write(g06_array[6]); //set g6 bit spi.write(g06_array[5]); //set g5 bit spi.write(g06_array[4]); //set g4 bit spi.write(g06_array[3]); //set g3 bit spi.write(g06_array[2]); //set g2 bit spi.write(g06_array[1]); //set g1 bit spi.write(g06_array[0]);//set g0 bit //set red bits spi.write(r06_array[7]);//set r7 bit spi.write(r06_array[6]); //set r6 bit spi.write(r06_array[5]); //set r5 bit spi.write(r06_array[4]); //set r4 bit spi.write(r06_array[3]); //set r3 bit spi.write(r06_array[2]); //set r2 bit spi.write(r06_array[1]); //set r1 bit spi.write(r06_array[0]); //set r0 bit //set blue bits spi.write(b06_array[7]); //set b7 bit spi.write(b06_array[6]); //set b6 bit spi.write(b06_array[5]); //set b5 bit spi.write(b06_array[4]); //set b4 bit spi.write(b06_array[3]); //set b3 bit spi.write(b06_array[2]); //set b2 bit spi.write(b06_array[1]); //set b1 bit spi.write(b06_array[0]); //set b0 bit //LED7 //set green bits spi.write(g07_array[7]); //set g7 bit spi.write(g07_array[6]); //set g6 bit spi.write(g07_array[5]); //set g5 bit spi.write(g07_array[4]); //set g4 bit spi.write(g07_array[3]); //set g3 bit spi.write(g07_array[2]); //set g2 bit spi.write(g07_array[1]); //set g1 bit spi.write(g07_array[0]);//set g0 bit //set red bits spi.write(r07_array[7]);//set r7 bit spi.write(r07_array[6]); //set r6 bit spi.write(r07_array[5]); //set r5 bit spi.write(r07_array[4]); //set r4 bit spi.write(r07_array[3]); //set r3 bit spi.write(r07_array[2]); //set r2 bit spi.write(r07_array[1]); //set r1 bit spi.write(r07_array[0]); //set r0 bit //set blue bits spi.write(b07_array[7]); //set b7 bit spi.write(b07_array[6]); //set b6 bit spi.write(b07_array[5]); //set b5 bit spi.write(b07_array[4]); //set b4 bit spi.write(b07_array[3]); //set b3 bit spi.write(b07_array[2]); //set b2 bit spi.write(b07_array[1]); //set b1 bit spi.write(b07_array[0]); //set b0 bit //room2 //LED0 //set green bits spi.write(g10_array[7]); //set g7 bit spi.write(g10_array[6]); //set g6 bit spi.write(g10_array[5]); //set g5 bit spi.write(g10_array[4]); //set g4 bit spi.write(g10_array[3]); //set g3 bit spi.write(g10_array[2]); //set g2 bit spi.write(g10_array[1]); //set g1 bit spi.write(g10_array[0]);//set g0 bit //set red bits spi.write(r10_array[7]);//set r7 bit spi.write(r10_array[6]); //set r6 bit spi.write(r10_array[5]); //set r5 bit spi.write(r10_array[4]); //set r4 bit spi.write(r10_array[3]); //set r3 bit spi.write(r10_array[2]); //set r2 bit spi.write(r10_array[1]); //set r1 bit spi.write(r10_array[0]); //set r0 bit //set blue bits spi.write(b10_array[7]); //set b7 bit spi.write(b10_array[6]); //set b6 bit spi.write(b10_array[5]); //set b5 bit spi.write(b10_array[4]); //set b4 bit spi.write(b10_array[3]); //set b3 bit spi.write(b10_array[2]); //set b2 bit spi.write(b10_array[1]); //set b1 bit spi.write(b10_array[0]); //set b0 bit //LED1 //set green bits spi.write(g11_array[7]); //set g7 bit spi.write(g11_array[6]); //set g6 bit spi.write(g11_array[5]); //set g5 bit spi.write(g11_array[4]); //set g4 bit spi.write(g11_array[3]); //set g3 bit spi.write(g11_array[2]); //set g2 bit spi.write(g11_array[1]); //set g1 bit spi.write(g11_array[0]);//set g0 bit //set red bits spi.write(r11_array[7]);//set r7 bit spi.write(r11_array[6]); //set r6 bit spi.write(r11_array[5]); //set r5 bit spi.write(r11_array[4]); //set r4 bit spi.write(r11_array[3]); //set r3 bit spi.write(r11_array[2]); //set r2 bit spi.write(r11_array[1]); //set r1 bit spi.write(r11_array[0]); //set r0 bit //set blue bits spi.write(b11_array[7]); //set b7 bit spi.write(b11_array[6]); //set b6 bit spi.write(b11_array[5]); //set b5 bit spi.write(b11_array[4]); //set b4 bit spi.write(b11_array[3]); //set b3 bit spi.write(b11_array[2]); //set b2 bit spi.write(b11_array[1]); //set b1 bit spi.write(b11_array[0]); //set b0 bit //LED2 //set green bits spi.write(g12_array[7]); //set g7 bit spi.write(g12_array[6]); //set g6 bit spi.write(g12_array[5]); //set g5 bit spi.write(g12_array[4]); //set g4 bit spi.write(g12_array[3]); //set g3 bit spi.write(g12_array[2]); //set g2 bit spi.write(g12_array[1]); //set g1 bit spi.write(g12_array[0]);//set g0 bit //set red bits spi.write(r12_array[7]);//set r7 bit spi.write(r12_array[6]); //set r6 bit spi.write(r12_array[5]); //set r5 bit spi.write(r12_array[4]); //set r4 bit spi.write(r12_array[3]); //set r3 bit spi.write(r12_array[2]); //set r2 bit spi.write(r12_array[1]); //set r1 bit spi.write(r12_array[0]); //set r0 bit //set blue bits spi.write(b12_array[7]); //set b7 bit spi.write(b12_array[6]); //set b6 bit spi.write(b12_array[5]); //set b5 bit spi.write(b12_array[4]); //set b4 bit spi.write(b12_array[3]); //set b3 bit spi.write(b12_array[2]); //set b2 bit spi.write(b12_array[1]); //set b1 bit spi.write(b12_array[0]); //set b0 bit //LED3 //set green bits spi.write(g13_array[7]); //set g7 bit spi.write(g13_array[6]); //set g6 bit spi.write(g13_array[5]); //set g5 bit spi.write(g13_array[4]); //set g4 bit spi.write(g13_array[3]); //set g3 bit spi.write(g13_array[2]); //set g2 bit spi.write(g13_array[1]); //set g1 bit spi.write(g13_array[0]);//set g0 bit //set red bits spi.write(r13_array[7]);//set r7 bit spi.write(r13_array[6]); //set r6 bit spi.write(r13_array[5]); //set r5 bit spi.write(r13_array[4]); //set r4 bit spi.write(r13_array[3]); //set r3 bit spi.write(r13_array[2]); //set r2 bit spi.write(r13_array[1]); //set r1 bit spi.write(r13_array[0]); //set r0 bit //set blue bits spi.write(b13_array[7]); //set b7 bit spi.write(b13_array[6]); //set b6 bit spi.write(b13_array[5]); //set b5 bit spi.write(b13_array[4]); //set b4 bit spi.write(b13_array[3]); //set b3 bit spi.write(b13_array[2]); //set b2 bit spi.write(b13_array[1]); //set b1 bit spi.write(b13_array[0]); //set b0 bit //LED4 //set green bits spi.write(g14_array[7]); //set g7 bit spi.write(g14_array[6]); //set g6 bit spi.write(g14_array[5]); //set g5 bit spi.write(g14_array[4]); //set g4 bit spi.write(g14_array[3]); //set g3 bit spi.write(g14_array[2]); //set g2 bit spi.write(g14_array[1]); //set g1 bit spi.write(g14_array[0]);//set g0 bit //set red bits spi.write(r14_array[7]);//set r7 bit spi.write(r14_array[6]); //set r6 bit spi.write(r14_array[5]); //set r5 bit spi.write(r14_array[4]); //set r4 bit spi.write(r14_array[3]); //set r3 bit spi.write(r14_array[2]); //set r2 bit spi.write(r14_array[1]); //set r1 bit spi.write(r14_array[0]); //set r0 bit //set blue bits spi.write(b14_array[7]); //set b7 bit spi.write(b14_array[6]); //set b6 bit spi.write(b14_array[5]); //set b5 bit spi.write(b14_array[4]); //set b4 bit spi.write(b14_array[3]); //set b3 bit spi.write(b14_array[2]); //set b2 bit spi.write(b14_array[1]); //set b1 bit spi.write(b14_array[0]); //set b0 bit //LED5 //set green bits spi.write(g15_array[7]); //set g7 bit spi.write(g15_array[6]); //set g6 bit spi.write(g15_array[5]); //set g5 bit spi.write(g15_array[4]); //set g4 bit spi.write(g15_array[3]); //set g3 bit spi.write(g15_array[2]); //set g2 bit spi.write(g15_array[1]); //set g1 bit spi.write(g15_array[0]);//set g0 bit //set red bits spi.write(r15_array[7]);//set r7 bit spi.write(r15_array[6]); //set r6 bit spi.write(r15_array[5]); //set r5 bit spi.write(r15_array[4]); //set r4 bit spi.write(r15_array[3]); //set r3 bit spi.write(r15_array[2]); //set r2 bit spi.write(r15_array[1]); //set r1 bit spi.write(r15_array[0]); //set r0 bit //set blue bits spi.write(b15_array[7]); //set b7 bit spi.write(b15_array[6]); //set b6 bit spi.write(b15_array[5]); //set b5 bit spi.write(b15_array[4]); //set b4 bit spi.write(b15_array[3]); //set b3 bit spi.write(b15_array[2]); //set b2 bit spi.write(b15_array[1]); //set b1 bit spi.write(b15_array[0]); //set b0 bit //LED6 //set green bits spi.write(g16_array[7]); //set g7 bit spi.write(g16_array[6]); //set g6 bit spi.write(g16_array[5]); //set g5 bit spi.write(g16_array[4]); //set g4 bit spi.write(g16_array[3]); //set g3 bit spi.write(g16_array[2]); //set g2 bit spi.write(g16_array[1]); //set g1 bit spi.write(g16_array[0]);//set g0 bit //set red bits spi.write(r16_array[7]);//set r7 bit spi.write(r16_array[6]); //set r6 bit spi.write(r16_array[5]); //set r5 bit spi.write(r16_array[4]); //set r4 bit spi.write(r16_array[3]); //set r3 bit spi.write(r16_array[2]); //set r2 bit spi.write(r16_array[1]); //set r1 bit spi.write(r16_array[0]); //set r0 bit //set blue bits spi.write(b16_array[7]); //set b7 bit spi.write(b16_array[6]); //set b6 bit spi.write(b16_array[5]); //set b5 bit spi.write(b16_array[4]); //set b4 bit spi.write(b16_array[3]); //set b3 bit spi.write(b16_array[2]); //set b2 bit spi.write(b16_array[1]); //set b1 bit spi.write(b16_array[0]); //set b0 bit //LED7 //set green bits spi.write(g17_array[7]); //set g7 bit spi.write(g17_array[6]); //set g6 bit spi.write(g17_array[5]); //set g5 bit spi.write(g17_array[4]); //set g4 bit spi.write(g17_array[3]); //set g3 bit spi.write(g17_array[2]); //set g2 bit spi.write(g17_array[1]); //set g1 bit spi.write(g17_array[0]);//set g0 bit //set red bits spi.write(r17_array[7]);//set r7 bit spi.write(r17_array[6]); //set r6 bit spi.write(r17_array[5]); //set r5 bit spi.write(r17_array[4]); //set r4 bit spi.write(r17_array[3]); //set r3 bit spi.write(r17_array[2]); //set r2 bit spi.write(r17_array[1]); //set r1 bit spi.write(r17_array[0]); //set r0 bit //set blue bits spi.write(b17_array[7]); //set b7 bit spi.write(b17_array[6]); //set b6 bit spi.write(b17_array[5]); //set b5 bit spi.write(b17_array[4]); //set b4 bit spi.write(b17_array[3]); //set b3 bit spi.write(b17_array[2]); //set b2 bit spi.write(b17_array[1]); //set b1 bit spi.write(b17_array[0]); //set b0 bit //room3 //LED0 //set green bits spi.write(g20_array[7]); //set g7 bit spi.write(g20_array[6]); //set g6 bit spi.write(g20_array[5]); //set g5 bit spi.write(g20_array[4]); //set g4 bit spi.write(g20_array[3]); //set g3 bit spi.write(g20_array[2]); //set g2 bit spi.write(g20_array[1]); //set g1 bit spi.write(g20_array[0]);//set g0 bit //set red bits spi.write(r20_array[7]);//set r7 bit spi.write(r20_array[6]); //set r6 bit spi.write(r20_array[5]); //set r5 bit spi.write(r20_array[4]); //set r4 bit spi.write(r20_array[3]); //set r3 bit spi.write(r20_array[2]); //set r2 bit spi.write(r20_array[1]); //set r1 bit spi.write(r20_array[0]); //set r0 bit //set blue bits spi.write(b20_array[7]); //set b7 bit spi.write(b20_array[6]); //set b6 bit spi.write(b20_array[5]); //set b5 bit spi.write(b20_array[4]); //set b4 bit spi.write(b20_array[3]); //set b3 bit spi.write(b20_array[2]); //set b2 bit spi.write(b20_array[1]); //set b1 bit spi.write(b20_array[0]); //set b0 bit //LED1 //set green bits spi.write(g21_array[7]); //set g7 bit spi.write(g21_array[6]); //set g6 bit spi.write(g21_array[5]); //set g5 bit spi.write(g21_array[4]); //set g4 bit spi.write(g21_array[3]); //set g3 bit spi.write(g21_array[2]); //set g2 bit spi.write(g21_array[1]); //set g1 bit spi.write(g21_array[0]);//set g0 bit //set red bits spi.write(r21_array[7]);//set r7 bit spi.write(r21_array[6]); //set r6 bit spi.write(r21_array[5]); //set r5 bit spi.write(r21_array[4]); //set r4 bit spi.write(r21_array[3]); //set r3 bit spi.write(r21_array[2]); //set r2 bit spi.write(r21_array[1]); //set r1 bit spi.write(r21_array[0]); //set r0 bit //set blue bits spi.write(b21_array[7]); //set b7 bit spi.write(b21_array[6]); //set b6 bit spi.write(b21_array[5]); //set b5 bit spi.write(b21_array[4]); //set b4 bit spi.write(b21_array[3]); //set b3 bit spi.write(b21_array[2]); //set b2 bit spi.write(b21_array[1]); //set b1 bit spi.write(b21_array[0]); //set b0 bit //LED2 //set green bits spi.write(g22_array[7]); //set g7 bit spi.write(g22_array[6]); //set g6 bit spi.write(g22_array[5]); //set g5 bit spi.write(g22_array[4]); //set g4 bit spi.write(g22_array[3]); //set g3 bit spi.write(g22_array[2]); //set g2 bit spi.write(g22_array[1]); //set g1 bit spi.write(g22_array[0]);//set g0 bit //set red bits spi.write(r22_array[7]);//set r7 bit spi.write(r22_array[6]); //set r6 bit spi.write(r22_array[5]); //set r5 bit spi.write(r22_array[4]); //set r4 bit spi.write(r22_array[3]); //set r3 bit spi.write(r22_array[2]); //set r2 bit spi.write(r22_array[1]); //set r1 bit spi.write(r22_array[0]); //set r0 bit //set blue bits spi.write(b22_array[7]); //set b7 bit spi.write(b22_array[6]); //set b6 bit spi.write(b22_array[5]); //set b5 bit spi.write(b22_array[4]); //set b4 bit spi.write(b22_array[3]); //set b3 bit spi.write(b22_array[2]); //set b2 bit spi.write(b22_array[1]); //set b1 bit spi.write(b22_array[0]); //set b0 bit //LED3 //set green bits spi.write(g23_array[7]); //set g7 bit spi.write(g23_array[6]); //set g6 bit spi.write(g23_array[5]); //set g5 bit spi.write(g23_array[4]); //set g4 bit spi.write(g23_array[3]); //set g3 bit spi.write(g23_array[2]); //set g2 bit spi.write(g23_array[1]); //set g1 bit spi.write(g23_array[0]);//set g0 bit //set red bits spi.write(r23_array[7]);//set r7 bit spi.write(r23_array[6]); //set r6 bit spi.write(r23_array[5]); //set r5 bit spi.write(r23_array[4]); //set r4 bit spi.write(r23_array[3]); //set r3 bit spi.write(r23_array[2]); //set r2 bit spi.write(r23_array[1]); //set r1 bit spi.write(r23_array[0]); //set r0 bit //set blue bits spi.write(b23_array[7]); //set b7 bit spi.write(b23_array[6]); //set b6 bit spi.write(b23_array[5]); //set b5 bit spi.write(b23_array[4]); //set b4 bit spi.write(b23_array[3]); //set b3 bit spi.write(b23_array[2]); //set b2 bit spi.write(b23_array[1]); //set b1 bit spi.write(b23_array[0]); //set b0 bit //LED4 //set green bits spi.write(g24_array[7]); //set g7 bit spi.write(g24_array[6]); //set g6 bit spi.write(g24_array[5]); //set g5 bit spi.write(g24_array[4]); //set g4 bit spi.write(g24_array[3]); //set g3 bit spi.write(g24_array[2]); //set g2 bit spi.write(g24_array[1]); //set g1 bit spi.write(g24_array[0]);//set g0 bit //set red bits spi.write(r24_array[7]);//set r7 bit spi.write(r24_array[6]); //set r6 bit spi.write(r24_array[5]); //set r5 bit spi.write(r24_array[4]); //set r4 bit spi.write(r24_array[3]); //set r3 bit spi.write(r24_array[2]); //set r2 bit spi.write(r24_array[1]); //set r1 bit spi.write(r24_array[0]); //set r0 bit //set blue bits spi.write(b24_array[7]); //set b7 bit spi.write(b24_array[6]); //set b6 bit spi.write(b24_array[5]); //set b5 bit spi.write(b24_array[4]); //set b4 bit spi.write(b24_array[3]); //set b3 bit spi.write(b24_array[2]); //set b2 bit spi.write(b24_array[1]); //set b1 bit spi.write(b24_array[0]); //set b0 bit //LED5 //set green bits spi.write(g25_array[7]); //set g7 bit spi.write(g25_array[6]); //set g6 bit spi.write(g25_array[5]); //set g5 bit spi.write(g25_array[4]); //set g4 bit spi.write(g25_array[3]); //set g3 bit spi.write(g25_array[2]); //set g2 bit spi.write(g25_array[1]); //set g1 bit spi.write(g25_array[0]);//set g0 bit //set red bits spi.write(r25_array[7]);//set r7 bit spi.write(r25_array[6]); //set r6 bit spi.write(r25_array[5]); //set r5 bit spi.write(r25_array[4]); //set r4 bit spi.write(r25_array[3]); //set r3 bit spi.write(r25_array[2]); //set r2 bit spi.write(r25_array[1]); //set r1 bit spi.write(r25_array[0]); //set r0 bit //set blue bits spi.write(b25_array[7]); //set b7 bit spi.write(b25_array[6]); //set b6 bit spi.write(b25_array[5]); //set b5 bit spi.write(b25_array[4]); //set b4 bit spi.write(b25_array[3]); //set b3 bit spi.write(b25_array[2]); //set b2 bit spi.write(b25_array[1]); //set b1 bit spi.write(b25_array[0]); //set b0 bit //LED6 //set green bits spi.write(g26_array[7]); //set g7 bit spi.write(g26_array[6]); //set g6 bit spi.write(g26_array[5]); //set g5 bit spi.write(g26_array[4]); //set g4 bit spi.write(g26_array[3]); //set g3 bit spi.write(g26_array[2]); //set g2 bit spi.write(g26_array[1]); //set g1 bit spi.write(g26_array[0]);//set g0 bit //set red bits spi.write(r26_array[7]);//set r7 bit spi.write(r26_array[6]); //set r6 bit spi.write(r26_array[5]); //set r5 bit spi.write(r26_array[4]); //set r4 bit spi.write(r26_array[3]); //set r3 bit spi.write(r26_array[2]); //set r2 bit spi.write(r26_array[1]); //set r1 bit spi.write(r26_array[0]); //set r0 bit //set blue bits spi.write(b26_array[7]); //set b7 bit spi.write(b26_array[6]); //set b6 bit spi.write(b26_array[5]); //set b5 bit spi.write(b26_array[4]); //set b4 bit spi.write(b26_array[3]); //set b3 bit spi.write(b26_array[2]); //set b2 bit spi.write(b26_array[1]); //set b1 bit spi.write(b26_array[0]); //set b0 bit //LED7 //set green bits spi.write(g27_array[7]); //set g7 bit spi.write(g27_array[6]); //set g6 bit spi.write(g27_array[5]); //set g5 bit spi.write(g27_array[4]); //set g4 bit spi.write(g27_array[3]); //set g3 bit spi.write(g27_array[2]); //set g2 bit spi.write(g27_array[1]); //set g1 bit spi.write(g27_array[0]);//set g0 bit //set red bits spi.write(r27_array[7]);//set r7 bit spi.write(r27_array[6]); //set r6 bit spi.write(r27_array[5]); //set r5 bit spi.write(r27_array[4]); //set r4 bit spi.write(r27_array[3]); //set r3 bit spi.write(r27_array[2]); //set r2 bit spi.write(r27_array[1]); //set r1 bit spi.write(r27_array[0]); //set r0 bit //set blue bits spi.write(b27_array[7]); //set b7 bit spi.write(b27_array[6]); //set b6 bit spi.write(b27_array[5]); //set b5 bit spi.write(b27_array[4]); //set b4 bit spi.write(b27_array[3]); //set b3 bit spi.write(b27_array[2]); //set b2 bit spi.write(b27_array[1]); //set b1 bit spi.write(b27_array[0]); //set b0 bit //room4 //LED0 //set green bits spi.write(g30_array[7]); //set g7 bit spi.write(g30_array[6]); //set g6 bit spi.write(g30_array[5]); //set g5 bit spi.write(g30_array[4]); //set g4 bit spi.write(g30_array[3]); //set g3 bit spi.write(g30_array[2]); //set g2 bit spi.write(g30_array[1]); //set g1 bit spi.write(g30_array[0]);//set g0 bit //set red bits spi.write(r30_array[7]);//set r7 bit spi.write(r30_array[6]); //set r6 bit spi.write(r30_array[5]); //set r5 bit spi.write(r30_array[4]); //set r4 bit spi.write(r30_array[3]); //set r3 bit spi.write(r30_array[2]); //set r2 bit spi.write(r30_array[1]); //set r1 bit spi.write(r30_array[0]); //set r0 bit //set blue bits spi.write(b30_array[7]); //set b7 bit spi.write(b30_array[6]); //set b6 bit spi.write(b30_array[5]); //set b5 bit spi.write(b30_array[4]); //set b4 bit spi.write(b30_array[3]); //set b3 bit spi.write(b30_array[2]); //set b2 bit spi.write(b30_array[1]); //set b1 bit spi.write(b30_array[0]); //set b0 bit //LED1 //set green bits spi.write(g31_array[7]); //set g7 bit spi.write(g31_array[6]); //set g6 bit spi.write(g31_array[5]); //set g5 bit spi.write(g31_array[4]); //set g4 bit spi.write(g31_array[3]); //set g3 bit spi.write(g31_array[2]); //set g2 bit spi.write(g31_array[1]); //set g1 bit spi.write(g31_array[0]);//set g0 bit //set red bits spi.write(r31_array[7]);//set r7 bit spi.write(r31_array[6]); //set r6 bit spi.write(r31_array[5]); //set r5 bit spi.write(r31_array[4]); //set r4 bit spi.write(r31_array[3]); //set r3 bit spi.write(r31_array[2]); //set r2 bit spi.write(r31_array[1]); //set r1 bit spi.write(r31_array[0]); //set r0 bit //set blue bits spi.write(b31_array[7]); //set b7 bit spi.write(b31_array[6]); //set b6 bit spi.write(b31_array[5]); //set b5 bit spi.write(b31_array[4]); //set b4 bit spi.write(b31_array[3]); //set b3 bit spi.write(b31_array[2]); //set b2 bit spi.write(b31_array[1]); //set b1 bit spi.write(b31_array[0]); //set b0 bit //LED2 //set green bits spi.write(g32_array[7]); //set g7 bit spi.write(g32_array[6]); //set g6 bit spi.write(g32_array[5]); //set g5 bit spi.write(g32_array[4]); //set g4 bit spi.write(g32_array[3]); //set g3 bit spi.write(g32_array[2]); //set g2 bit spi.write(g32_array[1]); //set g1 bit spi.write(g32_array[0]);//set g0 bit //set red bits spi.write(r32_array[7]);//set r7 bit spi.write(r32_array[6]); //set r6 bit spi.write(r32_array[5]); //set r5 bit spi.write(r32_array[4]); //set r4 bit spi.write(r32_array[3]); //set r3 bit spi.write(r32_array[2]); //set r2 bit spi.write(r32_array[1]); //set r1 bit spi.write(r32_array[0]); //set r0 bit //set blue bits spi.write(b32_array[7]); //set b7 bit spi.write(b32_array[6]); //set b6 bit spi.write(b32_array[5]); //set b5 bit spi.write(b32_array[4]); //set b4 bit spi.write(b32_array[3]); //set b3 bit spi.write(b32_array[2]); //set b2 bit spi.write(b32_array[1]); //set b1 bit spi.write(b32_array[0]); //set b0 bit //LED3 //set green bits spi.write(g33_array[7]); //set g7 bit spi.write(g33_array[6]); //set g6 bit spi.write(g33_array[5]); //set g5 bit spi.write(g33_array[4]); //set g4 bit spi.write(g33_array[3]); //set g3 bit spi.write(g33_array[2]); //set g2 bit spi.write(g33_array[1]); //set g1 bit spi.write(g33_array[0]);//set g0 bit //set red bits spi.write(r33_array[7]);//set r7 bit spi.write(r33_array[6]); //set r6 bit spi.write(r33_array[5]); //set r5 bit spi.write(r33_array[4]); //set r4 bit spi.write(r33_array[3]); //set r3 bit spi.write(r33_array[2]); //set r2 bit spi.write(r33_array[1]); //set r1 bit spi.write(r33_array[0]); //set r0 bit //set blue bits spi.write(b33_array[7]); //set b7 bit spi.write(b33_array[6]); //set b6 bit spi.write(b33_array[5]); //set b5 bit spi.write(b33_array[4]); //set b4 bit spi.write(b33_array[3]); //set b3 bit spi.write(b33_array[2]); //set b2 bit spi.write(b33_array[1]); //set b1 bit spi.write(b33_array[0]); //set b0 bit //LED4 //set green bits spi.write(g34_array[7]); //set g7 bit spi.write(g34_array[6]); //set g6 bit spi.write(g34_array[5]); //set g5 bit spi.write(g34_array[4]); //set g4 bit spi.write(g34_array[3]); //set g3 bit spi.write(g34_array[2]); //set g2 bit spi.write(g34_array[1]); //set g1 bit spi.write(g34_array[0]);//set g0 bit //set red bits spi.write(r34_array[7]);//set r7 bit spi.write(r34_array[6]); //set r6 bit spi.write(r34_array[5]); //set r5 bit spi.write(r34_array[4]); //set r4 bit spi.write(r34_array[3]); //set r3 bit spi.write(r34_array[2]); //set r2 bit spi.write(r34_array[1]); //set r1 bit spi.write(r34_array[0]); //set r0 bit //set blue bits spi.write(b34_array[7]); //set b7 bit spi.write(b34_array[6]); //set b6 bit spi.write(b34_array[5]); //set b5 bit spi.write(b34_array[4]); //set b4 bit spi.write(b34_array[3]); //set b3 bit spi.write(b34_array[2]); //set b2 bit spi.write(b34_array[1]); //set b1 bit spi.write(b34_array[0]); //set b0 bit //LED5 //set green bits spi.write(g35_array[7]); //set g7 bit spi.write(g35_array[6]); //set g6 bit spi.write(g35_array[5]); //set g5 bit spi.write(g35_array[4]); //set g4 bit spi.write(g35_array[3]); //set g3 bit spi.write(g35_array[2]); //set g2 bit spi.write(g35_array[1]); //set g1 bit spi.write(g35_array[0]);//set g0 bit //set red bits spi.write(r35_array[7]);//set r7 bit spi.write(r35_array[6]); //set r6 bit spi.write(r35_array[5]); //set r5 bit spi.write(r35_array[4]); //set r4 bit spi.write(r35_array[3]); //set r3 bit spi.write(r35_array[2]); //set r2 bit spi.write(r35_array[1]); //set r1 bit spi.write(r35_array[0]); //set r0 bit //set blue bits spi.write(b35_array[7]); //set b7 bit spi.write(b35_array[6]); //set b6 bit spi.write(b35_array[5]); //set b5 bit spi.write(b35_array[4]); //set b4 bit spi.write(b35_array[3]); //set b3 bit spi.write(b35_array[2]); //set b2 bit spi.write(b35_array[1]); //set b1 bit spi.write(b35_array[0]); //set b0 bit //LED6 //set green bits spi.write(g36_array[7]); //set g7 bit spi.write(g36_array[6]); //set g6 bit spi.write(g36_array[5]); //set g5 bit spi.write(g36_array[4]); //set g4 bit spi.write(g36_array[3]); //set g3 bit spi.write(g36_array[2]); //set g2 bit spi.write(g36_array[1]); //set g1 bit spi.write(g36_array[0]);//set g0 bit //set red bits spi.write(r36_array[7]);//set r7 bit spi.write(r36_array[6]); //set r6 bit spi.write(r36_array[5]); //set r5 bit spi.write(r36_array[4]); //set r4 bit spi.write(r36_array[3]); //set r3 bit spi.write(r36_array[2]); //set r2 bit spi.write(r36_array[1]); //set r1 bit spi.write(r36_array[0]); //set r0 bit //set blue bits spi.write(b36_array[7]); //set b7 bit spi.write(b36_array[6]); //set b6 bit spi.write(b36_array[5]); //set b5 bit spi.write(b36_array[4]); //set b4 bit spi.write(b36_array[3]); //set b3 bit spi.write(b36_array[2]); //set b2 bit spi.write(b36_array[1]); //set b1 bit spi.write(b36_array[0]); //set b0 bit //LED7 //set green bits spi.write(g37_array[7]); //set g7 bit spi.write(g37_array[6]); //set g6 bit spi.write(g37_array[5]); //set g5 bit spi.write(g37_array[4]); //set g4 bit spi.write(g37_array[3]); //set g3 bit spi.write(g37_array[2]); //set g2 bit spi.write(g37_array[1]); //set g1 bit spi.write(g37_array[0]);//set g0 bit //set red bits spi.write(r37_array[7]);//set r7 bit spi.write(r37_array[6]); //set r6 bit spi.write(r37_array[5]); //set r5 bit spi.write(r37_array[4]); //set r4 bit spi.write(r37_array[3]); //set r3 bit spi.write(r37_array[2]); //set r2 bit spi.write(r37_array[1]); //set r1 bit spi.write(r37_array[0]); //set r0 bit //set blue bits spi.write(b37_array[7]); //set b7 bit spi.write(b37_array[6]); //set b6 bit spi.write(b37_array[5]); //set b5 bit spi.write(b37_array[4]); //set b4 bit spi.write(b37_array[3]); //set b3 bit spi.write(b37_array[2]); //set b2 bit spi.write(b37_array[1]); //set b1 bit spi.write(b37_array[0]); //set b0 bit //wait for latch wait_us(60); } int * decimalToBinary(int n) // converts decimal value to 8 bit array of 1's (0xFF0) and 0's (0xF00) { int reminder; int i=0; int static binary[8]; //initialize to 00000000 while (n!=0) { reminder=n%2; if(reminder == 1){ binary[i] = 0xFF0; } if(reminder == 0){ binary[i] = 0xF00; } n = n/2; i++; } //sets the remainder of the digits to 0xF00 if n reaches 0 before i = 7 for(;i<8;i++){ binary[i] = 0xF00; } return binary; } void spi_init(){ //initializes spi port to send 0 bit length spi.format(14, 0); //set spi at 14 bits/byte with clock phase and clock polarity at mode 0 spi.frequency(10600000); //set frequency of spi clock at 96/9 - 10.6MHz 94.3 ns bit time length }