updated

Fork of neopixels_spi by Ivan Yohuno

Committer:
el12moe
Date:
Wed May 13 17:52:07 2015 +0000
Revision:
1:2023e348c15f
Parent:
0:22b6f7132818
The code for controlling the light modes from the app;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ivanyohuno 0:22b6f7132818 1 #include "mbed.h"
ivanyohuno 0:22b6f7132818 2 #include "neopixels_spi.h"
ivanyohuno 0:22b6f7132818 3 #include <string.h>
ivanyohuno 0:22b6f7132818 4 #include <stdio.h>
ivanyohuno 0:22b6f7132818 5
ivanyohuno 0:22b6f7132818 6 /*
ivanyohuno 0:22b6f7132818 7 neopixel_spi v03
ivanyohuno 0:22b6f7132818 8 Created By: Ivan Yohuno
ivanyohuno 0:22b6f7132818 9 SSID: 200717683
ivanyohuno 0:22b6f7132818 10
ivanyohuno 0:22b6f7132818 11 Notes:
ivanyohuno 0:22b6f7132818 12 -Code to be run on WS2812 neopixel LEDs, can run with a single pixel or a strip of max 8 leds connected together
ivanyohuno 0:22b6f7132818 13 -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
ivanyohuno 0:22b6f7132818 14
ivanyohuno 0:22b6f7132818 15 Features:
ivanyohuno 0:22b6f7132818 16 -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
ivanyohuno 0:22b6f7132818 17 -SetRGBStrip // sets colour of RGB strip of 8
ivanyohuno 0:22b6f7132818 18 -setRGBStrips //sets colours of 4 RGB strips of 8
ivanyohuno 0:22b6f7132818 19 colours 2D 4x3 matrix:
ivanyohuno 0:22b6f7132818 20 {{room 1 strip red, room 1 strip green, room 1 strip blue},
ivanyohuno 0:22b6f7132818 21 {room 2 strip red, room 2 strip green, room 3 strip blue},
ivanyohuno 0:22b6f7132818 22 {room 3 strip red, room 3 strip green, room 3 strip blue}
ivanyohuno 0:22b6f7132818 23 }
ivanyohuno 0:22b6f7132818 24 -SetRGBPixels // sets an RGB strip of 8 to individual colours using a 2D 8x3 matrix
ivanyohuno 0:22b6f7132818 25 colours 2D 8x3 matrix:
ivanyohuno 0:22b6f7132818 26 {{1st pixel red, 1st pixel blue, 1st pixel green},
ivanyohuno 0:22b6f7132818 27 {2nd pixel red, 2nd pixel blue, 2nd pixel green},
ivanyohuno 0:22b6f7132818 28 {3rd pixel red, 3rd pixel blue, 3rd pixel green},
ivanyohuno 0:22b6f7132818 29 {4th pixel red, 4th pixel blue, 4th pixel green},
ivanyohuno 0:22b6f7132818 30 {5th pixel red, 5th pixel blue, 5th pixel green},
ivanyohuno 0:22b6f7132818 31 {6th pixel red, 6th pixel blue, 6th pixel green},
ivanyohuno 0:22b6f7132818 32 {7th pixel red, 7th pixel blue, 7th pixel green},
ivanyohuno 0:22b6f7132818 33 {8th pixel red, 8th pixel blue, 8th pixel green}
ivanyohuno 0:22b6f7132818 34 }
ivanyohuno 0:22b6f7132818 35
ivanyohuno 0:22b6f7132818 36 */
ivanyohuno 0:22b6f7132818 37 SPI spi(p5, p6, p7);//pin for SPI communication - p5 MOSI p5 MISO p6 SCLK
ivanyohuno 0:22b6f7132818 38 SPI spi2(p11, p12, p13);//pin for SPI communication - p5 MOSI p5 MISO p6 SCLK
el12moe 1:2023e348c15f 39
ivanyohuno 0:22b6f7132818 40
ivanyohuno 0:22b6f7132818 41
ivanyohuno 0:22b6f7132818 42 void neopixels_spi::setRGBStrip1(int r, int g, int b){
ivanyohuno 0:22b6f7132818 43 int r_array[8];
ivanyohuno 0:22b6f7132818 44 int g_array[8];
ivanyohuno 0:22b6f7132818 45 int b_array[8];
ivanyohuno 0:22b6f7132818 46 memcpy(r_array, decimalToBinary(r), sizeof(r_array));
ivanyohuno 0:22b6f7132818 47 memcpy(g_array, decimalToBinary(g), sizeof(g_array));
ivanyohuno 0:22b6f7132818 48 memcpy(b_array, decimalToBinary(b), sizeof(b_array));
ivanyohuno 0:22b6f7132818 49
ivanyohuno 0:22b6f7132818 50 //send commands to LED Driver
ivanyohuno 0:22b6f7132818 51 //initialize SPI
ivanyohuno 0:22b6f7132818 52 spi_init();
el12moe 1:2023e348c15f 53 for(int x=0; x<4; x++){
el12moe 1:2023e348c15f 54 //LED0
ivanyohuno 0:22b6f7132818 55 //set green bits
ivanyohuno 0:22b6f7132818 56 spi.write(g_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 57 spi.write(g_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 58 spi.write(g_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 59 spi.write(g_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 60 spi.write(g_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 61 spi.write(g_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 62 spi.write(g_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 63 spi.write(g_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 64 //set red bits
ivanyohuno 0:22b6f7132818 65 spi.write(r_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 66 spi.write(r_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 67 spi.write(r_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 68 spi.write(r_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 69 spi.write(r_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 70 spi.write(r_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 71 spi.write(r_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 72 spi.write(r_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 73 //set blue bits
ivanyohuno 0:22b6f7132818 74 spi.write(b_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 75 spi.write(b_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 76 spi.write(b_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 77 spi.write(b_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 78 spi.write(b_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 79 spi.write(b_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 80 spi.write(b_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 81 spi.write(b_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 82 //LED1
ivanyohuno 0:22b6f7132818 83 //set green bits
ivanyohuno 0:22b6f7132818 84 spi.write(g_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 85 spi.write(g_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 86 spi.write(g_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 87 spi.write(g_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 88 spi.write(g_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 89 spi.write(g_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 90 spi.write(g_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 91 spi.write(g_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 92 //set red bits
ivanyohuno 0:22b6f7132818 93 spi.write(r_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 94 spi.write(r_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 95 spi.write(r_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 96 spi.write(r_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 97 spi.write(r_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 98 spi.write(r_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 99 spi.write(r_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 100 spi.write(r_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 101 //set blue bits
ivanyohuno 0:22b6f7132818 102 spi.write(b_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 103 spi.write(b_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 104 spi.write(b_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 105 spi.write(b_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 106 spi.write(b_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 107 spi.write(b_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 108 spi.write(b_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 109 spi.write(b_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 110 //LED2
ivanyohuno 0:22b6f7132818 111 //set green bits
ivanyohuno 0:22b6f7132818 112 spi.write(g_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 113 spi.write(g_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 114 spi.write(g_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 115 spi.write(g_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 116 spi.write(g_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 117 spi.write(g_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 118 spi.write(g_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 119 spi.write(g_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 120 //set red bits
ivanyohuno 0:22b6f7132818 121 spi.write(r_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 122 spi.write(r_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 123 spi.write(r_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 124 spi.write(r_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 125 spi.write(r_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 126 spi.write(r_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 127 spi.write(r_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 128 spi.write(r_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 129 //set blue bits
ivanyohuno 0:22b6f7132818 130 spi.write(b_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 131 spi.write(b_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 132 spi.write(b_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 133 spi.write(b_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 134 spi.write(b_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 135 spi.write(b_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 136 spi.write(b_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 137 spi.write(b_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 138 //LED3
ivanyohuno 0:22b6f7132818 139 //set green bits
ivanyohuno 0:22b6f7132818 140 spi.write(g_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 141 spi.write(g_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 142 spi.write(g_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 143 spi.write(g_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 144 spi.write(g_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 145 spi.write(g_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 146 spi.write(g_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 147 spi.write(g_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 148 //set red bits
ivanyohuno 0:22b6f7132818 149 spi.write(r_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 150 spi.write(r_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 151 spi.write(r_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 152 spi.write(r_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 153 spi.write(r_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 154 spi.write(r_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 155 spi.write(r_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 156 spi.write(r_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 157 //set blue bits
ivanyohuno 0:22b6f7132818 158 spi.write(b_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 159 spi.write(b_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 160 spi.write(b_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 161 spi.write(b_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 162 spi.write(b_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 163 spi.write(b_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 164 spi.write(b_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 165 spi.write(b_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 166 //LED4
ivanyohuno 0:22b6f7132818 167 //set green bits
ivanyohuno 0:22b6f7132818 168 spi.write(g_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 169 spi.write(g_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 170 spi.write(g_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 171 spi.write(g_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 172 spi.write(g_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 173 spi.write(g_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 174 spi.write(g_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 175 spi.write(g_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 176 //set red bits
ivanyohuno 0:22b6f7132818 177 spi.write(r_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 178 spi.write(r_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 179 spi.write(r_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 180 spi.write(r_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 181 spi.write(r_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 182 spi.write(r_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 183 spi.write(r_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 184 spi.write(r_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 185 //set blue bits
ivanyohuno 0:22b6f7132818 186 spi.write(b_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 187 spi.write(b_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 188 spi.write(b_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 189 spi.write(b_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 190 spi.write(b_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 191 spi.write(b_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 192 spi.write(b_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 193 spi.write(b_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 194 //LED5
ivanyohuno 0:22b6f7132818 195 //set green bits
ivanyohuno 0:22b6f7132818 196 spi.write(g_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 197 spi.write(g_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 198 spi.write(g_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 199 spi.write(g_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 200 spi.write(g_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 201 spi.write(g_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 202 spi.write(g_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 203 spi.write(g_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 204 //set red bits
ivanyohuno 0:22b6f7132818 205 spi.write(r_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 206 spi.write(r_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 207 spi.write(r_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 208 spi.write(r_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 209 spi.write(r_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 210 spi.write(r_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 211 spi.write(r_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 212 spi.write(r_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 213 //set blue bits
ivanyohuno 0:22b6f7132818 214 spi.write(b_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 215 spi.write(b_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 216 spi.write(b_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 217 spi.write(b_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 218 spi.write(b_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 219 spi.write(b_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 220 spi.write(b_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 221 spi.write(b_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 222 //LED6
ivanyohuno 0:22b6f7132818 223 //set green bits
ivanyohuno 0:22b6f7132818 224
ivanyohuno 0:22b6f7132818 225 spi.write(g_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 226 spi.write(g_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 227 spi.write(g_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 228 spi.write(g_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 229 spi.write(g_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 230 spi.write(g_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 231 spi.write(g_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 232 spi.write(g_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 233 //set red bits
ivanyohuno 0:22b6f7132818 234 spi.write(r_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 235 spi.write(r_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 236 spi.write(r_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 237 spi.write(r_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 238 spi.write(r_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 239 spi.write(r_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 240 spi.write(r_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 241 spi.write(r_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 242 //set blue bits
ivanyohuno 0:22b6f7132818 243 spi.write(b_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 244 spi.write(b_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 245 spi.write(b_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 246 spi.write(b_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 247 spi.write(b_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 248 spi.write(b_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 249 spi.write(b_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 250 spi.write(b_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 251 //LED7
ivanyohuno 0:22b6f7132818 252 //set green bits
ivanyohuno 0:22b6f7132818 253 spi.write(g_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 254 spi.write(g_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 255 spi.write(g_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 256 spi.write(g_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 257 spi.write(g_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 258 spi.write(g_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 259 spi.write(g_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 260 spi.write(g_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 261 //set red bits
ivanyohuno 0:22b6f7132818 262 spi.write(r_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 263 spi.write(r_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 264 spi.write(r_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 265 spi.write(r_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 266 spi.write(r_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 267 spi.write(r_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 268 spi.write(r_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 269 spi.write(r_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 270 //set blue bits
ivanyohuno 0:22b6f7132818 271 spi.write(b_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 272 spi.write(b_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 273 spi.write(b_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 274 spi.write(b_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 275 spi.write(b_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 276 spi.write(b_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 277 spi.write(b_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 278 spi.write(b_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 279
ivanyohuno 0:22b6f7132818 280 //wait for latch
el12moe 1:2023e348c15f 281 wait_us(50);
el12moe 1:2023e348c15f 282 }
el12moe 1:2023e348c15f 283
ivanyohuno 0:22b6f7132818 284 }
ivanyohuno 0:22b6f7132818 285
ivanyohuno 0:22b6f7132818 286 void neopixels_spi::setRGBStrip2(int r, int g, int b){
ivanyohuno 0:22b6f7132818 287 int r_array[8];
ivanyohuno 0:22b6f7132818 288 int g_array[8];
ivanyohuno 0:22b6f7132818 289 int b_array[8];
ivanyohuno 0:22b6f7132818 290 memcpy(r_array, decimalToBinary(r), sizeof(r_array));
ivanyohuno 0:22b6f7132818 291 memcpy(g_array, decimalToBinary(g), sizeof(g_array));
ivanyohuno 0:22b6f7132818 292 memcpy(b_array, decimalToBinary(b), sizeof(b_array));
ivanyohuno 0:22b6f7132818 293
ivanyohuno 0:22b6f7132818 294 //send commands to LED Driver
ivanyohuno 0:22b6f7132818 295 //initialize spi
ivanyohuno 0:22b6f7132818 296 spi_init();
el12moe 1:2023e348c15f 297 for(int i = 0; i<4; i++){
el12moe 1:2023e348c15f 298 //LED0
ivanyohuno 0:22b6f7132818 299 //set green bits
ivanyohuno 0:22b6f7132818 300 spi2.write(g_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 301 spi2.write(g_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 302 spi2.write(g_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 303 spi2.write(g_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 304 spi2.write(g_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 305 spi2.write(g_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 306 spi2.write(g_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 307 spi2.write(g_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 308 //set red bits
ivanyohuno 0:22b6f7132818 309 spi2.write(r_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 310 spi2.write(r_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 311 spi2.write(r_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 312 spi2.write(r_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 313 spi2.write(r_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 314 spi2.write(r_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 315 spi2.write(r_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 316 spi2.write(r_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 317 //set blue bits
ivanyohuno 0:22b6f7132818 318 spi2.write(b_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 319 spi2.write(b_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 320 spi2.write(b_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 321 spi2.write(b_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 322 spi2.write(b_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 323 spi2.write(b_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 324 spi2.write(b_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 325 spi2.write(b_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 326 //LED1
ivanyohuno 0:22b6f7132818 327 //set green bits
ivanyohuno 0:22b6f7132818 328 spi2.write(g_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 329 spi2.write(g_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 330 spi2.write(g_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 331 spi2.write(g_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 332 spi2.write(g_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 333 spi2.write(g_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 334 spi2.write(g_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 335 spi2.write(g_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 336 //set red bits
ivanyohuno 0:22b6f7132818 337 spi2.write(r_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 338 spi2.write(r_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 339 spi2.write(r_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 340 spi2.write(r_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 341 spi2.write(r_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 342 spi2.write(r_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 343 spi2.write(r_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 344 spi2.write(r_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 345 //set blue bits
ivanyohuno 0:22b6f7132818 346 spi2.write(b_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 347 spi2.write(b_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 348 spi2.write(b_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 349 spi2.write(b_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 350 spi2.write(b_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 351 spi2.write(b_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 352 spi2.write(b_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 353 spi2.write(b_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 354 //LED2
ivanyohuno 0:22b6f7132818 355 //set green bits
ivanyohuno 0:22b6f7132818 356 spi2.write(g_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 357 spi2.write(g_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 358 spi2.write(g_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 359 spi2.write(g_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 360 spi2.write(g_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 361 spi2.write(g_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 362 spi2.write(g_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 363 spi2.write(g_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 364 //set red bits
ivanyohuno 0:22b6f7132818 365 spi2.write(r_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 366 spi2.write(r_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 367 spi2.write(r_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 368 spi2.write(r_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 369 spi2.write(r_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 370 spi2.write(r_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 371 spi2.write(r_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 372 spi2.write(r_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 373 //set blue bits
ivanyohuno 0:22b6f7132818 374 spi2.write(b_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 375 spi2.write(b_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 376 spi2.write(b_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 377 spi2.write(b_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 378 spi2.write(b_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 379 spi2.write(b_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 380 spi2.write(b_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 381 spi2.write(b_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 382 //LED3
ivanyohuno 0:22b6f7132818 383 //set green bits
ivanyohuno 0:22b6f7132818 384 spi2.write(g_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 385 spi2.write(g_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 386 spi2.write(g_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 387 spi2.write(g_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 388 spi2.write(g_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 389 spi2.write(g_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 390 spi2.write(g_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 391 spi2.write(g_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 392 //set red bits
ivanyohuno 0:22b6f7132818 393 spi2.write(r_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 394 spi2.write(r_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 395 spi2.write(r_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 396 spi2.write(r_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 397 spi2.write(r_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 398 spi2.write(r_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 399 spi2.write(r_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 400 spi2.write(r_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 401 //set blue bits
ivanyohuno 0:22b6f7132818 402 spi2.write(b_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 403 spi2.write(b_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 404 spi2.write(b_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 405 spi2.write(b_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 406 spi2.write(b_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 407 spi2.write(b_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 408 spi2.write(b_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 409 spi2.write(b_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 410 //LED4
ivanyohuno 0:22b6f7132818 411 //set green bits
ivanyohuno 0:22b6f7132818 412 spi2.write(g_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 413 spi2.write(g_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 414 spi2.write(g_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 415 spi2.write(g_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 416 spi2.write(g_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 417 spi2.write(g_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 418 spi2.write(g_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 419 spi2.write(g_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 420 //set red bits
ivanyohuno 0:22b6f7132818 421 spi2.write(r_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 422 spi2.write(r_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 423 spi2.write(r_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 424 spi2.write(r_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 425 spi2.write(r_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 426 spi2.write(r_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 427 spi2.write(r_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 428 spi2.write(r_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 429 //set blue bits
ivanyohuno 0:22b6f7132818 430 spi2.write(b_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 431 spi2.write(b_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 432 spi2.write(b_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 433 spi2.write(b_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 434 spi2.write(b_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 435 spi2.write(b_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 436 spi2.write(b_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 437 spi2.write(b_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 438 //LED5
ivanyohuno 0:22b6f7132818 439 //set green bits
ivanyohuno 0:22b6f7132818 440 spi2.write(g_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 441 spi2.write(g_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 442 spi2.write(g_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 443 spi2.write(g_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 444 spi2.write(g_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 445 spi2.write(g_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 446 spi2.write(g_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 447 spi2.write(g_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 448 //set red bits
ivanyohuno 0:22b6f7132818 449 spi2.write(r_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 450 spi2.write(r_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 451 spi2.write(r_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 452 spi2.write(r_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 453 spi2.write(r_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 454 spi2.write(r_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 455 spi2.write(r_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 456 spi2.write(r_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 457 //set blue bits
ivanyohuno 0:22b6f7132818 458 spi2.write(b_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 459 spi2.write(b_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 460 spi2.write(b_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 461 spi2.write(b_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 462 spi2.write(b_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 463 spi2.write(b_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 464 spi2.write(b_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 465 spi2.write(b_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 466 //LED6
ivanyohuno 0:22b6f7132818 467 //set green bits
ivanyohuno 0:22b6f7132818 468
ivanyohuno 0:22b6f7132818 469 spi2.write(g_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 470 spi2.write(g_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 471 spi2.write(g_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 472 spi2.write(g_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 473 spi2.write(g_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 474 spi2.write(g_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 475 spi2.write(g_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 476 spi2.write(g_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 477 //set red bits
ivanyohuno 0:22b6f7132818 478 spi2.write(r_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 479 spi2.write(r_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 480 spi2.write(r_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 481 spi2.write(r_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 482 spi2.write(r_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 483 spi2.write(r_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 484 spi2.write(r_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 485 spi2.write(r_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 486 //set blue bits
ivanyohuno 0:22b6f7132818 487 spi2.write(b_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 488 spi2.write(b_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 489 spi2.write(b_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 490 spi2.write(b_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 491 spi2.write(b_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 492 spi2.write(b_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 493 spi2.write(b_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 494 spi2.write(b_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 495 //LED7
ivanyohuno 0:22b6f7132818 496 //set green bits
ivanyohuno 0:22b6f7132818 497 spi2.write(g_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 498 spi2.write(g_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 499 spi2.write(g_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 500 spi2.write(g_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 501 spi2.write(g_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 502 spi2.write(g_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 503 spi2.write(g_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 504 spi2.write(g_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 505 //set red bits
ivanyohuno 0:22b6f7132818 506 spi2.write(r_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 507 spi2.write(r_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 508 spi2.write(r_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 509 spi2.write(r_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 510 spi2.write(r_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 511 spi2.write(r_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 512 spi2.write(r_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 513 spi2.write(r_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 514 //set blue bits
ivanyohuno 0:22b6f7132818 515 spi2.write(b_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 516 spi2.write(b_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 517 spi2.write(b_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 518 spi2.write(b_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 519 spi2.write(b_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 520 spi2.write(b_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 521 spi2.write(b_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 522 spi2.write(b_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 523
ivanyohuno 0:22b6f7132818 524 //wait for latch
el12moe 1:2023e348c15f 525 wait_us(50);
el12moe 1:2023e348c15f 526 }
el12moe 1:2023e348c15f 527
ivanyohuno 0:22b6f7132818 528 }
ivanyohuno 0:22b6f7132818 529
ivanyohuno 0:22b6f7132818 530 void neopixels_spi::setRGBPixels1(int colours[8][3]){
ivanyohuno 0:22b6f7132818 531 //translate int values to array of 0xF00 (0) and 0xFF0 (1) binary
ivanyohuno 0:22b6f7132818 532 int r0_array[8]; //LED0
ivanyohuno 0:22b6f7132818 533 int g0_array[8];
ivanyohuno 0:22b6f7132818 534 int b0_array[8];
ivanyohuno 0:22b6f7132818 535 memcpy(r0_array, decimalToBinary(colours[0][0]), sizeof(r0_array));
ivanyohuno 0:22b6f7132818 536 memcpy(g0_array, decimalToBinary(colours[0][1]), sizeof(g0_array));
ivanyohuno 0:22b6f7132818 537 memcpy(b0_array, decimalToBinary(colours[0][2]), sizeof(b0_array));
ivanyohuno 0:22b6f7132818 538 int r1_array[8]; //LED1
ivanyohuno 0:22b6f7132818 539 int g1_array[8];
ivanyohuno 0:22b6f7132818 540 int b1_array[8];
ivanyohuno 0:22b6f7132818 541 memcpy(r1_array, decimalToBinary(colours[1][0]), sizeof(r1_array));
ivanyohuno 0:22b6f7132818 542 memcpy(g1_array, decimalToBinary(colours[1][1]), sizeof(g1_array));
ivanyohuno 0:22b6f7132818 543 memcpy(b1_array, decimalToBinary(colours[1][2]), sizeof(b1_array));
ivanyohuno 0:22b6f7132818 544 int r2_array[8]; //LED2
ivanyohuno 0:22b6f7132818 545 int g2_array[8];
ivanyohuno 0:22b6f7132818 546 int b2_array[8];
ivanyohuno 0:22b6f7132818 547 memcpy(r2_array, decimalToBinary(colours[2][0]), sizeof(r2_array));
ivanyohuno 0:22b6f7132818 548 memcpy(g2_array, decimalToBinary(colours[2][1]), sizeof(g2_array));
ivanyohuno 0:22b6f7132818 549 memcpy(b2_array, decimalToBinary(colours[2][2]), sizeof(b2_array));
ivanyohuno 0:22b6f7132818 550 int r3_array[8]; //LED3
ivanyohuno 0:22b6f7132818 551 int g3_array[8];
ivanyohuno 0:22b6f7132818 552 int b3_array[8];
ivanyohuno 0:22b6f7132818 553 memcpy(r3_array, decimalToBinary(colours[3][0]), sizeof(r3_array));
ivanyohuno 0:22b6f7132818 554 memcpy(g3_array, decimalToBinary(colours[3][1]), sizeof(g3_array));
ivanyohuno 0:22b6f7132818 555 memcpy(b3_array, decimalToBinary(colours[3][2]), sizeof(b3_array));
ivanyohuno 0:22b6f7132818 556 int r4_array[8]; //LED4
ivanyohuno 0:22b6f7132818 557 int g4_array[8];
ivanyohuno 0:22b6f7132818 558 int b4_array[8];
ivanyohuno 0:22b6f7132818 559 memcpy(r4_array, decimalToBinary(colours[4][0]), sizeof(r4_array));
ivanyohuno 0:22b6f7132818 560 memcpy(g4_array, decimalToBinary(colours[4][1]), sizeof(g4_array));
ivanyohuno 0:22b6f7132818 561 memcpy(b4_array, decimalToBinary(colours[4][2]), sizeof(b4_array));
ivanyohuno 0:22b6f7132818 562 int r5_array[8]; //LED5
ivanyohuno 0:22b6f7132818 563 int g5_array[8];
ivanyohuno 0:22b6f7132818 564 int b5_array[8];
ivanyohuno 0:22b6f7132818 565 memcpy(r5_array, decimalToBinary(colours[5][0]), sizeof(r5_array));
ivanyohuno 0:22b6f7132818 566 memcpy(g5_array, decimalToBinary(colours[5][1]), sizeof(g5_array));
ivanyohuno 0:22b6f7132818 567 memcpy(b5_array, decimalToBinary(colours[5][2]), sizeof(b5_array));
ivanyohuno 0:22b6f7132818 568 int r6_array[8]; //LED6
ivanyohuno 0:22b6f7132818 569 int g6_array[8];
ivanyohuno 0:22b6f7132818 570 int b6_array[8];
ivanyohuno 0:22b6f7132818 571 memcpy(r6_array, decimalToBinary(colours[6][0]), sizeof(r6_array));
ivanyohuno 0:22b6f7132818 572 memcpy(g6_array, decimalToBinary(colours[6][1]), sizeof(g6_array));
ivanyohuno 0:22b6f7132818 573 memcpy(b6_array, decimalToBinary(colours[6][2]), sizeof(b6_array));
ivanyohuno 0:22b6f7132818 574 int r7_array[8]; //LED7
ivanyohuno 0:22b6f7132818 575 int g7_array[8];
ivanyohuno 0:22b6f7132818 576 int b7_array[8];
ivanyohuno 0:22b6f7132818 577 memcpy(r7_array, decimalToBinary(colours[7][0]), sizeof(r7_array));
ivanyohuno 0:22b6f7132818 578 memcpy(g7_array, decimalToBinary(colours[7][1]), sizeof(g7_array));
ivanyohuno 0:22b6f7132818 579 memcpy(b7_array, decimalToBinary(colours[7][2]), sizeof(b7_array));
ivanyohuno 0:22b6f7132818 580
ivanyohuno 0:22b6f7132818 581 //send commands to LED Driver
ivanyohuno 0:22b6f7132818 582 //initialize SPI
ivanyohuno 0:22b6f7132818 583 spi_init();
el12moe 1:2023e348c15f 584 for(int v = 0; v<4; v++){
el12moe 1:2023e348c15f 585 //LED0
ivanyohuno 0:22b6f7132818 586 //set green bits
ivanyohuno 0:22b6f7132818 587 spi.write(g0_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 588 spi.write(g0_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 589 spi.write(g0_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 590 spi.write(g0_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 591 spi.write(g0_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 592 spi.write(g0_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 593 spi.write(g0_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 594 spi.write(g0_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 595 //set red bits
ivanyohuno 0:22b6f7132818 596 spi.write(r0_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 597 spi.write(r0_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 598 spi.write(r0_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 599 spi.write(r0_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 600 spi.write(r0_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 601 spi.write(r0_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 602 spi.write(r0_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 603 spi.write(r0_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 604 //set blue bits
ivanyohuno 0:22b6f7132818 605 spi.write(b0_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 606 spi.write(b0_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 607 spi.write(b0_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 608 spi.write(b0_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 609 spi.write(b0_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 610 spi.write(b0_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 611 spi.write(b0_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 612 spi.write(b0_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 613 //LED1
ivanyohuno 0:22b6f7132818 614 //set green bits
ivanyohuno 0:22b6f7132818 615 spi.write(g1_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 616 spi.write(g1_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 617 spi.write(g1_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 618 spi.write(g1_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 619 spi.write(g1_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 620 spi.write(g1_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 621 spi.write(g1_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 622 spi.write(g1_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 623 //set red bits
ivanyohuno 0:22b6f7132818 624 spi.write(r1_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 625 spi.write(r1_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 626 spi.write(r1_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 627 spi.write(r1_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 628 spi.write(r1_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 629 spi.write(r1_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 630 spi.write(r1_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 631 spi.write(r1_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 632 //set blue bits
ivanyohuno 0:22b6f7132818 633 spi.write(b1_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 634 spi.write(b1_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 635 spi.write(b1_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 636 spi.write(b1_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 637 spi.write(b1_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 638 spi.write(b1_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 639 spi.write(b1_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 640 spi.write(b1_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 641 //LED2
ivanyohuno 0:22b6f7132818 642 //set green bits
ivanyohuno 0:22b6f7132818 643 spi.write(g2_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 644 spi.write(g2_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 645 spi.write(g2_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 646 spi.write(g2_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 647 spi.write(g2_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 648 spi.write(g2_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 649 spi.write(g2_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 650 spi.write(g2_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 651 //set red bits
ivanyohuno 0:22b6f7132818 652 spi.write(r2_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 653 spi.write(r2_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 654 spi.write(r2_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 655 spi.write(r2_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 656 spi.write(r2_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 657 spi.write(r2_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 658 spi.write(r2_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 659 spi.write(r2_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 660 //set blue bits
ivanyohuno 0:22b6f7132818 661 spi.write(b2_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 662 spi.write(b2_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 663 spi.write(b2_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 664 spi.write(b2_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 665 spi.write(b2_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 666 spi.write(b2_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 667 spi.write(b2_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 668 spi.write(b2_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 669 //LED3
ivanyohuno 0:22b6f7132818 670 //set green bits
ivanyohuno 0:22b6f7132818 671 spi.write(g3_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 672 spi.write(g3_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 673 spi.write(g3_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 674 spi.write(g3_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 675 spi.write(g3_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 676 spi.write(g3_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 677 spi.write(g3_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 678 spi.write(g3_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 679 //set red bits
ivanyohuno 0:22b6f7132818 680 spi.write(r3_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 681 spi.write(r3_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 682 spi.write(r3_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 683 spi.write(r3_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 684 spi.write(r3_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 685 spi.write(r3_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 686 spi.write(r3_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 687 spi.write(r3_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 688 //set blue bits
ivanyohuno 0:22b6f7132818 689 spi.write(b3_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 690 spi.write(b3_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 691 spi.write(b3_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 692 spi.write(b3_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 693 spi.write(b3_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 694 spi.write(b3_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 695 spi.write(b3_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 696 spi.write(b3_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 697 //LED4
ivanyohuno 0:22b6f7132818 698 //set green bits
ivanyohuno 0:22b6f7132818 699 spi.write(g4_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 700 spi.write(g4_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 701 spi.write(g4_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 702 spi.write(g4_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 703 spi.write(g4_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 704 spi.write(g4_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 705 spi.write(g4_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 706 spi.write(g4_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 707 //set red bits
ivanyohuno 0:22b6f7132818 708 spi.write(r4_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 709 spi.write(r4_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 710 spi.write(r4_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 711 spi.write(r4_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 712 spi.write(r4_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 713 spi.write(r4_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 714 spi.write(r4_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 715 spi.write(r4_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 716 //set blue bits
ivanyohuno 0:22b6f7132818 717 spi.write(b4_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 718 spi.write(b4_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 719 spi.write(b4_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 720 spi.write(b4_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 721 spi.write(b4_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 722 spi.write(b4_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 723 spi.write(b4_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 724 spi.write(b4_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 725 //LED5
ivanyohuno 0:22b6f7132818 726 //set green bits
ivanyohuno 0:22b6f7132818 727 spi.write(g5_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 728 spi.write(g5_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 729 spi.write(g5_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 730 spi.write(g5_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 731 spi.write(g5_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 732 spi.write(g5_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 733 spi.write(g5_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 734 spi.write(g5_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 735 //set red bits
ivanyohuno 0:22b6f7132818 736 spi.write(r5_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 737 spi.write(r5_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 738 spi.write(r5_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 739 spi.write(r5_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 740 spi.write(r5_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 741 spi.write(r5_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 742 spi.write(r5_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 743 spi.write(r5_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 744 //set blue bits
ivanyohuno 0:22b6f7132818 745 spi.write(b5_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 746 spi.write(b5_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 747 spi.write(b5_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 748 spi.write(b5_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 749 spi.write(b5_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 750 spi.write(b5_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 751 spi.write(b5_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 752 spi.write(b5_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 753 //LED6
ivanyohuno 0:22b6f7132818 754 //set green bits
ivanyohuno 0:22b6f7132818 755 spi.write(g6_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 756 spi.write(g6_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 757 spi.write(g6_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 758 spi.write(g6_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 759 spi.write(g6_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 760 spi.write(g6_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 761 spi.write(g6_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 762 spi.write(g6_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 763 //set red bits
ivanyohuno 0:22b6f7132818 764 spi.write(r6_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 765 spi.write(r6_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 766 spi.write(r6_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 767 spi.write(r6_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 768 spi.write(r6_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 769 spi.write(r6_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 770 spi.write(r6_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 771 spi.write(r6_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 772 //set blue bits
ivanyohuno 0:22b6f7132818 773 spi.write(b6_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 774 spi.write(b6_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 775 spi.write(b6_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 776 spi.write(b6_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 777 spi.write(b6_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 778 spi.write(b6_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 779 spi.write(b6_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 780 spi.write(b6_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 781 //LED7
ivanyohuno 0:22b6f7132818 782 //set green bits
ivanyohuno 0:22b6f7132818 783 spi.write(g7_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 784 spi.write(g7_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 785 spi.write(g7_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 786 spi.write(g7_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 787 spi.write(g7_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 788 spi.write(g7_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 789 spi.write(g7_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 790 spi.write(g7_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 791 //set red bits
ivanyohuno 0:22b6f7132818 792 spi.write(r7_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 793 spi.write(r7_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 794 spi.write(r7_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 795 spi.write(r7_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 796 spi.write(r7_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 797 spi.write(r7_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 798 spi.write(r7_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 799 spi.write(r7_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 800 //set blue bits
ivanyohuno 0:22b6f7132818 801 spi.write(b7_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 802 spi.write(b7_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 803 spi.write(b7_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 804 spi.write(b7_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 805 spi.write(b7_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 806 spi.write(b7_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 807 spi.write(b7_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 808 spi.write(b7_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 809 //wait for latch
el12moe 1:2023e348c15f 810 wait_us(50);
el12moe 1:2023e348c15f 811 }
el12moe 1:2023e348c15f 812
ivanyohuno 0:22b6f7132818 813 }
ivanyohuno 0:22b6f7132818 814
ivanyohuno 0:22b6f7132818 815 void neopixels_spi::setRGBPixels2(int colours[8][3]){
ivanyohuno 0:22b6f7132818 816 //translate int values to array of 0xF00 (0) and 0xFF0 (1) binary
ivanyohuno 0:22b6f7132818 817 int r0_array[8]; //LED0
ivanyohuno 0:22b6f7132818 818 int g0_array[8];
ivanyohuno 0:22b6f7132818 819 int b0_array[8];
ivanyohuno 0:22b6f7132818 820 memcpy(r0_array, decimalToBinary(colours[0][0]), sizeof(r0_array));
ivanyohuno 0:22b6f7132818 821 memcpy(g0_array, decimalToBinary(colours[0][1]), sizeof(g0_array));
ivanyohuno 0:22b6f7132818 822 memcpy(b0_array, decimalToBinary(colours[0][2]), sizeof(b0_array));
ivanyohuno 0:22b6f7132818 823 int r1_array[8]; //LED1
ivanyohuno 0:22b6f7132818 824 int g1_array[8];
ivanyohuno 0:22b6f7132818 825 int b1_array[8];
ivanyohuno 0:22b6f7132818 826 memcpy(r1_array, decimalToBinary(colours[1][0]), sizeof(r1_array));
ivanyohuno 0:22b6f7132818 827 memcpy(g1_array, decimalToBinary(colours[1][1]), sizeof(g1_array));
ivanyohuno 0:22b6f7132818 828 memcpy(b1_array, decimalToBinary(colours[1][2]), sizeof(b1_array));
ivanyohuno 0:22b6f7132818 829 int r2_array[8]; //LED2
ivanyohuno 0:22b6f7132818 830 int g2_array[8];
ivanyohuno 0:22b6f7132818 831 int b2_array[8];
ivanyohuno 0:22b6f7132818 832 memcpy(r2_array, decimalToBinary(colours[2][0]), sizeof(r2_array));
ivanyohuno 0:22b6f7132818 833 memcpy(g2_array, decimalToBinary(colours[2][1]), sizeof(g2_array));
ivanyohuno 0:22b6f7132818 834 memcpy(b2_array, decimalToBinary(colours[2][2]), sizeof(b2_array));
ivanyohuno 0:22b6f7132818 835 int r3_array[8]; //LED3
ivanyohuno 0:22b6f7132818 836 int g3_array[8];
ivanyohuno 0:22b6f7132818 837 int b3_array[8];
ivanyohuno 0:22b6f7132818 838 memcpy(r3_array, decimalToBinary(colours[3][0]), sizeof(r3_array));
ivanyohuno 0:22b6f7132818 839 memcpy(g3_array, decimalToBinary(colours[3][1]), sizeof(g3_array));
ivanyohuno 0:22b6f7132818 840 memcpy(b3_array, decimalToBinary(colours[3][2]), sizeof(b3_array));
ivanyohuno 0:22b6f7132818 841 int r4_array[8]; //LED4
ivanyohuno 0:22b6f7132818 842 int g4_array[8];
ivanyohuno 0:22b6f7132818 843 int b4_array[8];
ivanyohuno 0:22b6f7132818 844 memcpy(r4_array, decimalToBinary(colours[4][0]), sizeof(r4_array));
ivanyohuno 0:22b6f7132818 845 memcpy(g4_array, decimalToBinary(colours[4][1]), sizeof(g4_array));
ivanyohuno 0:22b6f7132818 846 memcpy(b4_array, decimalToBinary(colours[4][2]), sizeof(b4_array));
ivanyohuno 0:22b6f7132818 847 int r5_array[8]; //LED5
ivanyohuno 0:22b6f7132818 848 int g5_array[8];
ivanyohuno 0:22b6f7132818 849 int b5_array[8];
ivanyohuno 0:22b6f7132818 850 memcpy(r5_array, decimalToBinary(colours[5][0]), sizeof(r5_array));
ivanyohuno 0:22b6f7132818 851 memcpy(g5_array, decimalToBinary(colours[5][1]), sizeof(g5_array));
ivanyohuno 0:22b6f7132818 852 memcpy(b5_array, decimalToBinary(colours[5][2]), sizeof(b5_array));
ivanyohuno 0:22b6f7132818 853 int r6_array[8]; //LED6
ivanyohuno 0:22b6f7132818 854 int g6_array[8];
ivanyohuno 0:22b6f7132818 855 int b6_array[8];
ivanyohuno 0:22b6f7132818 856 memcpy(r6_array, decimalToBinary(colours[6][0]), sizeof(r6_array));
ivanyohuno 0:22b6f7132818 857 memcpy(g6_array, decimalToBinary(colours[6][1]), sizeof(g6_array));
ivanyohuno 0:22b6f7132818 858 memcpy(b6_array, decimalToBinary(colours[6][2]), sizeof(b6_array));
ivanyohuno 0:22b6f7132818 859 int r7_array[8]; //LED7
ivanyohuno 0:22b6f7132818 860 int g7_array[8];
ivanyohuno 0:22b6f7132818 861 int b7_array[8];
ivanyohuno 0:22b6f7132818 862 memcpy(r7_array, decimalToBinary(colours[7][0]), sizeof(r7_array));
ivanyohuno 0:22b6f7132818 863 memcpy(g7_array, decimalToBinary(colours[7][1]), sizeof(g7_array));
ivanyohuno 0:22b6f7132818 864 memcpy(b7_array, decimalToBinary(colours[7][2]), sizeof(b7_array));
ivanyohuno 0:22b6f7132818 865
ivanyohuno 0:22b6f7132818 866 //send commands to LED Driver
ivanyohuno 0:22b6f7132818 867 //initialize SPI
ivanyohuno 0:22b6f7132818 868 spi_init();
el12moe 1:2023e348c15f 869 for(int b = 0; b<4; b++){
el12moe 1:2023e348c15f 870 //LED0
ivanyohuno 0:22b6f7132818 871 //set green bits
ivanyohuno 0:22b6f7132818 872 spi2.write(g0_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 873 spi2.write(g0_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 874 spi2.write(g0_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 875 spi2.write(g0_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 876 spi2.write(g0_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 877 spi2.write(g0_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 878 spi2.write(g0_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 879 spi2.write(g0_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 880 //set red bits
ivanyohuno 0:22b6f7132818 881 spi2.write(r0_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 882 spi2.write(r0_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 883 spi2.write(r0_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 884 spi2.write(r0_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 885 spi2.write(r0_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 886 spi2.write(r0_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 887 spi2.write(r0_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 888 spi2.write(r0_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 889 //set blue bits
ivanyohuno 0:22b6f7132818 890 spi2.write(b0_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 891 spi2.write(b0_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 892 spi2.write(b0_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 893 spi2.write(b0_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 894 spi2.write(b0_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 895 spi2.write(b0_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 896 spi2.write(b0_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 897 spi2.write(b0_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 898 //LED1
ivanyohuno 0:22b6f7132818 899 //set green bits
ivanyohuno 0:22b6f7132818 900 spi2.write(g1_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 901 spi2.write(g1_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 902 spi2.write(g1_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 903 spi2.write(g1_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 904 spi2.write(g1_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 905 spi2.write(g1_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 906 spi2.write(g1_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 907 spi2.write(g1_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 908 //set red bits
ivanyohuno 0:22b6f7132818 909 spi2.write(r1_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 910 spi2.write(r1_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 911 spi2.write(r1_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 912 spi2.write(r1_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 913 spi2.write(r1_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 914 spi2.write(r1_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 915 spi2.write(r1_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 916 spi2.write(r1_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 917 //set blue bits
ivanyohuno 0:22b6f7132818 918 spi2.write(b1_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 919 spi2.write(b1_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 920 spi2.write(b1_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 921 spi2.write(b1_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 922 spi2.write(b1_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 923 spi2.write(b1_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 924 spi2.write(b1_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 925 spi2.write(b1_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 926 //LED2
ivanyohuno 0:22b6f7132818 927 //set green bits
ivanyohuno 0:22b6f7132818 928 spi2.write(g2_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 929 spi2.write(g2_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 930 spi2.write(g2_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 931 spi2.write(g2_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 932 spi2.write(g2_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 933 spi2.write(g2_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 934 spi2.write(g2_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 935 spi2.write(g2_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 936 //set red bits
ivanyohuno 0:22b6f7132818 937 spi2.write(r2_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 938 spi2.write(r2_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 939 spi2.write(r2_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 940 spi2.write(r2_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 941 spi2.write(r2_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 942 spi2.write(r2_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 943 spi2.write(r2_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 944 spi2.write(r2_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 945 //set blue bits
ivanyohuno 0:22b6f7132818 946 spi2.write(b2_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 947 spi2.write(b2_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 948 spi2.write(b2_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 949 spi2.write(b2_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 950 spi2.write(b2_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 951 spi2.write(b2_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 952 spi2.write(b2_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 953 spi2.write(b2_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 954 //LED3
ivanyohuno 0:22b6f7132818 955 //set green bits
ivanyohuno 0:22b6f7132818 956 spi2.write(g3_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 957 spi2.write(g3_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 958 spi2.write(g3_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 959 spi2.write(g3_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 960 spi2.write(g3_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 961 spi2.write(g3_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 962 spi2.write(g3_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 963 spi2.write(g3_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 964 //set red bits
ivanyohuno 0:22b6f7132818 965 spi2.write(r3_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 966 spi2.write(r3_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 967 spi2.write(r3_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 968 spi2.write(r3_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 969 spi2.write(r3_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 970 spi2.write(r3_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 971 spi2.write(r3_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 972 spi2.write(r3_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 973 //set blue bits
ivanyohuno 0:22b6f7132818 974 spi2.write(b3_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 975 spi2.write(b3_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 976 spi2.write(b3_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 977 spi2.write(b3_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 978 spi2.write(b3_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 979 spi2.write(b3_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 980 spi2.write(b3_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 981 spi2.write(b3_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 982 //LED4
ivanyohuno 0:22b6f7132818 983 //set green bits
ivanyohuno 0:22b6f7132818 984 spi2.write(g4_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 985 spi2.write(g4_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 986 spi2.write(g4_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 987 spi2.write(g4_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 988 spi2.write(g4_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 989 spi2.write(g4_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 990 spi2.write(g4_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 991 spi2.write(g4_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 992 //set red bits
ivanyohuno 0:22b6f7132818 993 spi2.write(r4_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 994 spi2.write(r4_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 995 spi2.write(r4_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 996 spi2.write(r4_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 997 spi2.write(r4_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 998 spi2.write(r4_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 999 spi2.write(r4_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 1000 spi2.write(r4_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 1001 //set blue bits
ivanyohuno 0:22b6f7132818 1002 spi2.write(b4_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 1003 spi2.write(b4_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 1004 spi2.write(b4_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 1005 spi2.write(b4_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 1006 spi2.write(b4_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 1007 spi2.write(b4_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 1008 spi2.write(b4_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 1009 spi2.write(b4_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 1010 //LED5
ivanyohuno 0:22b6f7132818 1011 //set green bits
ivanyohuno 0:22b6f7132818 1012 spi2.write(g5_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 1013 spi2.write(g5_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 1014 spi2.write(g5_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 1015 spi2.write(g5_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 1016 spi2.write(g5_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 1017 spi2.write(g5_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 1018 spi2.write(g5_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 1019 spi2.write(g5_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 1020 //set red bits
ivanyohuno 0:22b6f7132818 1021 spi2.write(r5_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 1022 spi2.write(r5_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 1023 spi2.write(r5_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 1024 spi2.write(r5_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 1025 spi2.write(r5_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 1026 spi2.write(r5_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 1027 spi2.write(r5_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 1028 spi2.write(r5_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 1029 //set blue bits
ivanyohuno 0:22b6f7132818 1030 spi2.write(b5_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 1031 spi2.write(b5_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 1032 spi2.write(b5_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 1033 spi2.write(b5_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 1034 spi2.write(b5_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 1035 spi2.write(b5_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 1036 spi2.write(b5_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 1037 spi2.write(b5_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 1038 //LED6
ivanyohuno 0:22b6f7132818 1039 //set green bits
ivanyohuno 0:22b6f7132818 1040 spi2.write(g6_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 1041 spi2.write(g6_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 1042 spi2.write(g6_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 1043 spi2.write(g6_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 1044 spi2.write(g6_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 1045 spi2.write(g6_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 1046 spi2.write(g6_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 1047 spi2.write(g6_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 1048 //set red bits
ivanyohuno 0:22b6f7132818 1049 spi2.write(r6_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 1050 spi2.write(r6_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 1051 spi2.write(r6_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 1052 spi2.write(r6_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 1053 spi2.write(r6_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 1054 spi2.write(r6_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 1055 spi2.write(r6_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 1056 spi2.write(r6_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 1057 //set blue bits
ivanyohuno 0:22b6f7132818 1058 spi2.write(b6_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 1059 spi2.write(b6_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 1060 spi2.write(b6_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 1061 spi2.write(b6_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 1062 spi2.write(b6_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 1063 spi2.write(b6_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 1064 spi2.write(b6_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 1065 spi2.write(b6_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 1066 //LED7
ivanyohuno 0:22b6f7132818 1067 //set green bits
ivanyohuno 0:22b6f7132818 1068 spi2.write(g7_array[7]); //set g7 bit
ivanyohuno 0:22b6f7132818 1069 spi2.write(g7_array[6]); //set g6 bit
ivanyohuno 0:22b6f7132818 1070 spi2.write(g7_array[5]); //set g5 bit
ivanyohuno 0:22b6f7132818 1071 spi2.write(g7_array[4]); //set g4 bit
ivanyohuno 0:22b6f7132818 1072 spi2.write(g7_array[3]); //set g3 bit
ivanyohuno 0:22b6f7132818 1073 spi2.write(g7_array[2]); //set g2 bit
ivanyohuno 0:22b6f7132818 1074 spi2.write(g7_array[1]); //set g1 bit
ivanyohuno 0:22b6f7132818 1075 spi2.write(g7_array[0]);//set g0 bit
ivanyohuno 0:22b6f7132818 1076 //set red bits
ivanyohuno 0:22b6f7132818 1077 spi2.write(r7_array[7]);//set r7 bit
ivanyohuno 0:22b6f7132818 1078 spi2.write(r7_array[6]); //set r6 bit
ivanyohuno 0:22b6f7132818 1079 spi2.write(r7_array[5]); //set r5 bit
ivanyohuno 0:22b6f7132818 1080 spi2.write(r7_array[4]); //set r4 bit
ivanyohuno 0:22b6f7132818 1081 spi2.write(r7_array[3]); //set r3 bit
ivanyohuno 0:22b6f7132818 1082 spi2.write(r7_array[2]); //set r2 bit
ivanyohuno 0:22b6f7132818 1083 spi2.write(r7_array[1]); //set r1 bit
ivanyohuno 0:22b6f7132818 1084 spi2.write(r7_array[0]); //set r0 bit
ivanyohuno 0:22b6f7132818 1085 //set blue bits
ivanyohuno 0:22b6f7132818 1086 spi2.write(b7_array[7]); //set b7 bit
ivanyohuno 0:22b6f7132818 1087 spi2.write(b7_array[6]); //set b6 bit
ivanyohuno 0:22b6f7132818 1088 spi2.write(b7_array[5]); //set b5 bit
ivanyohuno 0:22b6f7132818 1089 spi2.write(b7_array[4]); //set b4 bit
ivanyohuno 0:22b6f7132818 1090 spi2.write(b7_array[3]); //set b3 bit
ivanyohuno 0:22b6f7132818 1091 spi2.write(b7_array[2]); //set b2 bit
ivanyohuno 0:22b6f7132818 1092 spi2.write(b7_array[1]); //set b1 bit
ivanyohuno 0:22b6f7132818 1093 spi2.write(b7_array[0]); //set b0 bit
ivanyohuno 0:22b6f7132818 1094 //wait for latch
el12moe 1:2023e348c15f 1095 wait_us(50);
el12moe 1:2023e348c15f 1096 }
el12moe 1:2023e348c15f 1097
ivanyohuno 0:22b6f7132818 1098 }
ivanyohuno 0:22b6f7132818 1099 int * neopixels_spi ::decimalToBinary(int n) // converts decimal value to 8 bit array of 1's (0xFF0) and 0's (0xF00)
ivanyohuno 0:22b6f7132818 1100 {
ivanyohuno 0:22b6f7132818 1101 int reminder;
ivanyohuno 0:22b6f7132818 1102 int i=0;
ivanyohuno 0:22b6f7132818 1103 int static binary[8]; //initialize to 00000000
ivanyohuno 0:22b6f7132818 1104 while (n!=0)
ivanyohuno 0:22b6f7132818 1105 {
ivanyohuno 0:22b6f7132818 1106 reminder=n%2;
ivanyohuno 0:22b6f7132818 1107 if(reminder == 1){
ivanyohuno 0:22b6f7132818 1108 binary[i] = 0xFF0;
ivanyohuno 0:22b6f7132818 1109 }
ivanyohuno 0:22b6f7132818 1110 if(reminder == 0){
ivanyohuno 0:22b6f7132818 1111 binary[i] = 0xF00;
ivanyohuno 0:22b6f7132818 1112 }
ivanyohuno 0:22b6f7132818 1113 n = n/2;
ivanyohuno 0:22b6f7132818 1114 i++;
ivanyohuno 0:22b6f7132818 1115 }
ivanyohuno 0:22b6f7132818 1116 //sets the remainder of the digits to 0xF00 if n reaches 0 before i = 7
ivanyohuno 0:22b6f7132818 1117 for(;i<8;i++){
ivanyohuno 0:22b6f7132818 1118 binary[i] = 0xF00;
ivanyohuno 0:22b6f7132818 1119 }
ivanyohuno 0:22b6f7132818 1120 return binary;
ivanyohuno 0:22b6f7132818 1121 }
ivanyohuno 0:22b6f7132818 1122
ivanyohuno 0:22b6f7132818 1123 void neopixels_spi ::spi_init(){ //initializes spi port to send 0 bit length
ivanyohuno 0:22b6f7132818 1124 spi.format(14, 0); //set spi at 14 bits/byte with clock phase and clock polarity at mode 0
ivanyohuno 0:22b6f7132818 1125 spi.frequency(10600000); //set frequency of spi clock at 96/9 - 10.6MHz 94.3 ns bit time length
ivanyohuno 0:22b6f7132818 1126 spi2.format(14, 0); //set spi at 14 bits/byte with clock phase and clock polarity at mode 0
ivanyohuno 0:22b6f7132818 1127 spi2.frequency(10600000); //set frequency of spi clock at 96/9 - 10.6MHz 94.3 ns bit time length
ivanyohuno 0:22b6f7132818 1128
ivanyohuno 0:22b6f7132818 1129 }