updated
Fork of neopixels_spi by
neopixels_spi.cpp@0:22b6f7132818, 2015-05-12 (annotated)
- Committer:
- ivanyohuno
- Date:
- Tue May 12 14:32:12 2015 +0000
- Revision:
- 0:22b6f7132818
- Child:
- 1:2023e348c15f
Created NeoPixels library
Who changed what in which revision?
User | Revision | Line number | New 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 | //function declarations |
ivanyohuno | 0:22b6f7132818 | 37 | //void setRGBPixel(int r, int g, int b); //sets colour of one RGB Pixel |
ivanyohuno | 0:22b6f7132818 | 38 | void setRGBStrip1(int r, int g, int b); //sets colour of a strip of 8 RGB Pixels on pin 5 |
ivanyohuno | 0:22b6f7132818 | 39 | void setRGBStrip2(int r, int g, int b); //sets colour of a strip of 8 RGB Pixels on pin 11 |
ivanyohuno | 0:22b6f7132818 | 40 | void setRGBPixels1(int colours[8][3]); //sets sequence of colours for a strip of 8 RGB Pixels on pin 5 |
ivanyohuno | 0:22b6f7132818 | 41 | void setRGBPixels2(int colours[8][3]); //sets sequence of colours for a strip of 8 RGB Pixels on pin 11 |
ivanyohuno | 0:22b6f7132818 | 42 | void spi_init(); //initializes SPI pin at correct bit length and bit rate |
ivanyohuno | 0:22b6f7132818 | 43 | int * decimalToBinary(int n); //converts a decimal value between 0 and 255 to an 8 bit binary array of 0xF00 (0) and 0xFF0 (1) |
ivanyohuno | 0:22b6f7132818 | 44 | */ |
ivanyohuno | 0:22b6f7132818 | 45 | //initialize pins |
ivanyohuno | 0:22b6f7132818 | 46 | //DigitalOut volt(p16); //pin for LV voltage |
ivanyohuno | 0:22b6f7132818 | 47 | SPI spi(p5, p6, p7);//pin for SPI communication - p5 MOSI p5 MISO p6 SCLK |
ivanyohuno | 0:22b6f7132818 | 48 | SPI spi2(p11, p12, p13);//pin for SPI communication - p5 MOSI p5 MISO p6 SCLK |
ivanyohuno | 0:22b6f7132818 | 49 | //NeoStrip strip(p5,8); |
ivanyohuno | 0:22b6f7132818 | 50 | |
ivanyohuno | 0:22b6f7132818 | 51 | |
ivanyohuno | 0:22b6f7132818 | 52 | void neopixels_spi::setRGBStrip1(int r, int g, int b){ |
ivanyohuno | 0:22b6f7132818 | 53 | int r_array[8]; |
ivanyohuno | 0:22b6f7132818 | 54 | int g_array[8]; |
ivanyohuno | 0:22b6f7132818 | 55 | int b_array[8]; |
ivanyohuno | 0:22b6f7132818 | 56 | memcpy(r_array, decimalToBinary(r), sizeof(r_array)); |
ivanyohuno | 0:22b6f7132818 | 57 | memcpy(g_array, decimalToBinary(g), sizeof(g_array)); |
ivanyohuno | 0:22b6f7132818 | 58 | memcpy(b_array, decimalToBinary(b), sizeof(b_array)); |
ivanyohuno | 0:22b6f7132818 | 59 | |
ivanyohuno | 0:22b6f7132818 | 60 | //send commands to LED Driver |
ivanyohuno | 0:22b6f7132818 | 61 | //initialize SPI |
ivanyohuno | 0:22b6f7132818 | 62 | spi_init(); |
ivanyohuno | 0:22b6f7132818 | 63 | //LED0 |
ivanyohuno | 0:22b6f7132818 | 64 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 65 | spi.write(g_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 66 | spi.write(g_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 67 | spi.write(g_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 68 | spi.write(g_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 69 | spi.write(g_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 70 | spi.write(g_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 71 | spi.write(g_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 72 | spi.write(g_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 73 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 74 | spi.write(r_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 75 | spi.write(r_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 76 | spi.write(r_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 77 | spi.write(r_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 78 | spi.write(r_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 79 | spi.write(r_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 80 | spi.write(r_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 81 | spi.write(r_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 82 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 83 | spi.write(b_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 84 | spi.write(b_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 85 | spi.write(b_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 86 | spi.write(b_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 87 | spi.write(b_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 88 | spi.write(b_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 89 | spi.write(b_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 90 | spi.write(b_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 91 | //LED1 |
ivanyohuno | 0:22b6f7132818 | 92 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 93 | spi.write(g_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 94 | spi.write(g_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 95 | spi.write(g_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 96 | spi.write(g_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 97 | spi.write(g_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 98 | spi.write(g_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 99 | spi.write(g_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 100 | spi.write(g_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 101 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 102 | spi.write(r_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 103 | spi.write(r_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 104 | spi.write(r_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 105 | spi.write(r_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 106 | spi.write(r_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 107 | spi.write(r_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 108 | spi.write(r_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 109 | spi.write(r_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 110 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 111 | spi.write(b_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 112 | spi.write(b_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 113 | spi.write(b_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 114 | spi.write(b_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 115 | spi.write(b_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 116 | spi.write(b_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 117 | spi.write(b_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 118 | spi.write(b_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 119 | //LED2 |
ivanyohuno | 0:22b6f7132818 | 120 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 121 | spi.write(g_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 122 | spi.write(g_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 123 | spi.write(g_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 124 | spi.write(g_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 125 | spi.write(g_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 126 | spi.write(g_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 127 | spi.write(g_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 128 | spi.write(g_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 129 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 130 | spi.write(r_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 131 | spi.write(r_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 132 | spi.write(r_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 133 | spi.write(r_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 134 | spi.write(r_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 135 | spi.write(r_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 136 | spi.write(r_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 137 | spi.write(r_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 138 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 139 | spi.write(b_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 140 | spi.write(b_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 141 | spi.write(b_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 142 | spi.write(b_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 143 | spi.write(b_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 144 | spi.write(b_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 145 | spi.write(b_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 146 | spi.write(b_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 147 | //LED3 |
ivanyohuno | 0:22b6f7132818 | 148 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 149 | spi.write(g_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 150 | spi.write(g_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 151 | spi.write(g_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 152 | spi.write(g_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 153 | spi.write(g_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 154 | spi.write(g_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 155 | spi.write(g_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 156 | spi.write(g_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 157 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 158 | spi.write(r_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 159 | spi.write(r_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 160 | spi.write(r_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 161 | spi.write(r_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 162 | spi.write(r_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 163 | spi.write(r_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 164 | spi.write(r_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 165 | spi.write(r_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 166 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 167 | spi.write(b_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 168 | spi.write(b_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 169 | spi.write(b_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 170 | spi.write(b_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 171 | spi.write(b_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 172 | spi.write(b_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 173 | spi.write(b_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 174 | spi.write(b_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 175 | //LED4 |
ivanyohuno | 0:22b6f7132818 | 176 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 177 | spi.write(g_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 178 | spi.write(g_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 179 | spi.write(g_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 180 | spi.write(g_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 181 | spi.write(g_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 182 | spi.write(g_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 183 | spi.write(g_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 184 | spi.write(g_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 185 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 186 | spi.write(r_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 187 | spi.write(r_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 188 | spi.write(r_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 189 | spi.write(r_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 190 | spi.write(r_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 191 | spi.write(r_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 192 | spi.write(r_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 193 | spi.write(r_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 194 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 195 | spi.write(b_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 196 | spi.write(b_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 197 | spi.write(b_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 198 | spi.write(b_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 199 | spi.write(b_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 200 | spi.write(b_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 201 | spi.write(b_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 202 | spi.write(b_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 203 | //LED5 |
ivanyohuno | 0:22b6f7132818 | 204 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 205 | spi.write(g_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 206 | spi.write(g_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 207 | spi.write(g_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 208 | spi.write(g_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 209 | spi.write(g_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 210 | spi.write(g_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 211 | spi.write(g_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 212 | spi.write(g_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 213 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 214 | spi.write(r_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 215 | spi.write(r_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 216 | spi.write(r_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 217 | spi.write(r_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 218 | spi.write(r_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 219 | spi.write(r_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 220 | spi.write(r_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 221 | spi.write(r_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 222 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 223 | spi.write(b_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 224 | spi.write(b_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 225 | spi.write(b_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 226 | spi.write(b_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 227 | spi.write(b_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 228 | spi.write(b_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 229 | spi.write(b_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 230 | spi.write(b_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 231 | //LED6 |
ivanyohuno | 0:22b6f7132818 | 232 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 233 | |
ivanyohuno | 0:22b6f7132818 | 234 | spi.write(g_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 235 | spi.write(g_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 236 | spi.write(g_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 237 | spi.write(g_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 238 | spi.write(g_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 239 | spi.write(g_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 240 | spi.write(g_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 241 | spi.write(g_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 242 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 243 | spi.write(r_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 244 | spi.write(r_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 245 | spi.write(r_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 246 | spi.write(r_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 247 | spi.write(r_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 248 | spi.write(r_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 249 | spi.write(r_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 250 | spi.write(r_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 251 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 252 | spi.write(b_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 253 | spi.write(b_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 254 | spi.write(b_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 255 | spi.write(b_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 256 | spi.write(b_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 257 | spi.write(b_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 258 | spi.write(b_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 259 | spi.write(b_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 260 | //LED7 |
ivanyohuno | 0:22b6f7132818 | 261 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 262 | spi.write(g_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 263 | spi.write(g_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 264 | spi.write(g_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 265 | spi.write(g_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 266 | spi.write(g_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 267 | spi.write(g_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 268 | spi.write(g_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 269 | spi.write(g_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 270 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 271 | spi.write(r_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 272 | spi.write(r_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 273 | spi.write(r_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 274 | spi.write(r_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 275 | spi.write(r_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 276 | spi.write(r_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 277 | spi.write(r_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 278 | spi.write(r_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 279 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 280 | spi.write(b_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 281 | spi.write(b_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 282 | spi.write(b_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 283 | spi.write(b_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 284 | spi.write(b_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 285 | spi.write(b_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 286 | spi.write(b_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 287 | spi.write(b_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 288 | |
ivanyohuno | 0:22b6f7132818 | 289 | //wait for latch |
ivanyohuno | 0:22b6f7132818 | 290 | wait_us(60); |
ivanyohuno | 0:22b6f7132818 | 291 | } |
ivanyohuno | 0:22b6f7132818 | 292 | |
ivanyohuno | 0:22b6f7132818 | 293 | void neopixels_spi::setRGBStrip2(int r, int g, int b){ |
ivanyohuno | 0:22b6f7132818 | 294 | int r_array[8]; |
ivanyohuno | 0:22b6f7132818 | 295 | int g_array[8]; |
ivanyohuno | 0:22b6f7132818 | 296 | int b_array[8]; |
ivanyohuno | 0:22b6f7132818 | 297 | memcpy(r_array, decimalToBinary(r), sizeof(r_array)); |
ivanyohuno | 0:22b6f7132818 | 298 | memcpy(g_array, decimalToBinary(g), sizeof(g_array)); |
ivanyohuno | 0:22b6f7132818 | 299 | memcpy(b_array, decimalToBinary(b), sizeof(b_array)); |
ivanyohuno | 0:22b6f7132818 | 300 | |
ivanyohuno | 0:22b6f7132818 | 301 | //send commands to LED Driver |
ivanyohuno | 0:22b6f7132818 | 302 | //initialize spi |
ivanyohuno | 0:22b6f7132818 | 303 | spi_init(); |
ivanyohuno | 0:22b6f7132818 | 304 | //LED0 |
ivanyohuno | 0:22b6f7132818 | 305 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 306 | spi2.write(g_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 307 | spi2.write(g_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 308 | spi2.write(g_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 309 | spi2.write(g_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 310 | spi2.write(g_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 311 | spi2.write(g_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 312 | spi2.write(g_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 313 | spi2.write(g_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 314 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 315 | spi2.write(r_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 316 | spi2.write(r_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 317 | spi2.write(r_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 318 | spi2.write(r_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 319 | spi2.write(r_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 320 | spi2.write(r_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 321 | spi2.write(r_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 322 | spi2.write(r_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 323 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 324 | spi2.write(b_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 325 | spi2.write(b_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 326 | spi2.write(b_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 327 | spi2.write(b_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 328 | spi2.write(b_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 329 | spi2.write(b_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 330 | spi2.write(b_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 331 | spi2.write(b_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 332 | //LED1 |
ivanyohuno | 0:22b6f7132818 | 333 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 334 | spi2.write(g_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 335 | spi2.write(g_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 336 | spi2.write(g_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 337 | spi2.write(g_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 338 | spi2.write(g_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 339 | spi2.write(g_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 340 | spi2.write(g_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 341 | spi2.write(g_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 342 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 343 | spi2.write(r_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 344 | spi2.write(r_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 345 | spi2.write(r_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 346 | spi2.write(r_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 347 | spi2.write(r_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 348 | spi2.write(r_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 349 | spi2.write(r_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 350 | spi2.write(r_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 351 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 352 | spi2.write(b_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 353 | spi2.write(b_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 354 | spi2.write(b_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 355 | spi2.write(b_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 356 | spi2.write(b_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 357 | spi2.write(b_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 358 | spi2.write(b_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 359 | spi2.write(b_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 360 | //LED2 |
ivanyohuno | 0:22b6f7132818 | 361 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 362 | spi2.write(g_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 363 | spi2.write(g_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 364 | spi2.write(g_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 365 | spi2.write(g_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 366 | spi2.write(g_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 367 | spi2.write(g_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 368 | spi2.write(g_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 369 | spi2.write(g_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 370 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 371 | spi2.write(r_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 372 | spi2.write(r_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 373 | spi2.write(r_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 374 | spi2.write(r_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 375 | spi2.write(r_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 376 | spi2.write(r_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 377 | spi2.write(r_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 378 | spi2.write(r_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 379 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 380 | spi2.write(b_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 381 | spi2.write(b_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 382 | spi2.write(b_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 383 | spi2.write(b_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 384 | spi2.write(b_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 385 | spi2.write(b_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 386 | spi2.write(b_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 387 | spi2.write(b_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 388 | //LED3 |
ivanyohuno | 0:22b6f7132818 | 389 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 390 | spi2.write(g_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 391 | spi2.write(g_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 392 | spi2.write(g_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 393 | spi2.write(g_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 394 | spi2.write(g_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 395 | spi2.write(g_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 396 | spi2.write(g_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 397 | spi2.write(g_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 398 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 399 | spi2.write(r_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 400 | spi2.write(r_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 401 | spi2.write(r_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 402 | spi2.write(r_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 403 | spi2.write(r_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 404 | spi2.write(r_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 405 | spi2.write(r_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 406 | spi2.write(r_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 407 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 408 | spi2.write(b_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 409 | spi2.write(b_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 410 | spi2.write(b_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 411 | spi2.write(b_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 412 | spi2.write(b_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 413 | spi2.write(b_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 414 | spi2.write(b_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 415 | spi2.write(b_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 416 | //LED4 |
ivanyohuno | 0:22b6f7132818 | 417 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 418 | spi2.write(g_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 419 | spi2.write(g_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 420 | spi2.write(g_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 421 | spi2.write(g_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 422 | spi2.write(g_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 423 | spi2.write(g_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 424 | spi2.write(g_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 425 | spi2.write(g_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 426 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 427 | spi2.write(r_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 428 | spi2.write(r_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 429 | spi2.write(r_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 430 | spi2.write(r_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 431 | spi2.write(r_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 432 | spi2.write(r_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 433 | spi2.write(r_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 434 | spi2.write(r_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 435 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 436 | spi2.write(b_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 437 | spi2.write(b_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 438 | spi2.write(b_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 439 | spi2.write(b_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 440 | spi2.write(b_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 441 | spi2.write(b_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 442 | spi2.write(b_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 443 | spi2.write(b_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 444 | //LED5 |
ivanyohuno | 0:22b6f7132818 | 445 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 446 | spi2.write(g_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 447 | spi2.write(g_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 448 | spi2.write(g_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 449 | spi2.write(g_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 450 | spi2.write(g_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 451 | spi2.write(g_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 452 | spi2.write(g_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 453 | spi2.write(g_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 454 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 455 | spi2.write(r_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 456 | spi2.write(r_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 457 | spi2.write(r_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 458 | spi2.write(r_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 459 | spi2.write(r_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 460 | spi2.write(r_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 461 | spi2.write(r_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 462 | spi2.write(r_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 463 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 464 | spi2.write(b_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 465 | spi2.write(b_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 466 | spi2.write(b_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 467 | spi2.write(b_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 468 | spi2.write(b_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 469 | spi2.write(b_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 470 | spi2.write(b_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 471 | spi2.write(b_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 472 | //LED6 |
ivanyohuno | 0:22b6f7132818 | 473 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 474 | |
ivanyohuno | 0:22b6f7132818 | 475 | spi2.write(g_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 476 | spi2.write(g_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 477 | spi2.write(g_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 478 | spi2.write(g_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 479 | spi2.write(g_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 480 | spi2.write(g_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 481 | spi2.write(g_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 482 | spi2.write(g_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 483 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 484 | spi2.write(r_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 485 | spi2.write(r_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 486 | spi2.write(r_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 487 | spi2.write(r_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 488 | spi2.write(r_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 489 | spi2.write(r_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 490 | spi2.write(r_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 491 | spi2.write(r_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 492 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 493 | spi2.write(b_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 494 | spi2.write(b_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 495 | spi2.write(b_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 496 | spi2.write(b_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 497 | spi2.write(b_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 498 | spi2.write(b_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 499 | spi2.write(b_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 500 | spi2.write(b_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 501 | //LED7 |
ivanyohuno | 0:22b6f7132818 | 502 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 503 | spi2.write(g_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 504 | spi2.write(g_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 505 | spi2.write(g_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 506 | spi2.write(g_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 507 | spi2.write(g_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 508 | spi2.write(g_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 509 | spi2.write(g_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 510 | spi2.write(g_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 511 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 512 | spi2.write(r_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 513 | spi2.write(r_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 514 | spi2.write(r_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 515 | spi2.write(r_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 516 | spi2.write(r_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 517 | spi2.write(r_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 518 | spi2.write(r_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 519 | spi2.write(r_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 520 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 521 | spi2.write(b_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 522 | spi2.write(b_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 523 | spi2.write(b_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 524 | spi2.write(b_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 525 | spi2.write(b_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 526 | spi2.write(b_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 527 | spi2.write(b_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 528 | spi2.write(b_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 529 | |
ivanyohuno | 0:22b6f7132818 | 530 | //wait for latch |
ivanyohuno | 0:22b6f7132818 | 531 | wait_us(60); |
ivanyohuno | 0:22b6f7132818 | 532 | } |
ivanyohuno | 0:22b6f7132818 | 533 | |
ivanyohuno | 0:22b6f7132818 | 534 | void neopixels_spi::setRGBPixels1(int colours[8][3]){ |
ivanyohuno | 0:22b6f7132818 | 535 | //translate int values to array of 0xF00 (0) and 0xFF0 (1) binary |
ivanyohuno | 0:22b6f7132818 | 536 | int r0_array[8]; //LED0 |
ivanyohuno | 0:22b6f7132818 | 537 | int g0_array[8]; |
ivanyohuno | 0:22b6f7132818 | 538 | int b0_array[8]; |
ivanyohuno | 0:22b6f7132818 | 539 | memcpy(r0_array, decimalToBinary(colours[0][0]), sizeof(r0_array)); |
ivanyohuno | 0:22b6f7132818 | 540 | memcpy(g0_array, decimalToBinary(colours[0][1]), sizeof(g0_array)); |
ivanyohuno | 0:22b6f7132818 | 541 | memcpy(b0_array, decimalToBinary(colours[0][2]), sizeof(b0_array)); |
ivanyohuno | 0:22b6f7132818 | 542 | int r1_array[8]; //LED1 |
ivanyohuno | 0:22b6f7132818 | 543 | int g1_array[8]; |
ivanyohuno | 0:22b6f7132818 | 544 | int b1_array[8]; |
ivanyohuno | 0:22b6f7132818 | 545 | memcpy(r1_array, decimalToBinary(colours[1][0]), sizeof(r1_array)); |
ivanyohuno | 0:22b6f7132818 | 546 | memcpy(g1_array, decimalToBinary(colours[1][1]), sizeof(g1_array)); |
ivanyohuno | 0:22b6f7132818 | 547 | memcpy(b1_array, decimalToBinary(colours[1][2]), sizeof(b1_array)); |
ivanyohuno | 0:22b6f7132818 | 548 | int r2_array[8]; //LED2 |
ivanyohuno | 0:22b6f7132818 | 549 | int g2_array[8]; |
ivanyohuno | 0:22b6f7132818 | 550 | int b2_array[8]; |
ivanyohuno | 0:22b6f7132818 | 551 | memcpy(r2_array, decimalToBinary(colours[2][0]), sizeof(r2_array)); |
ivanyohuno | 0:22b6f7132818 | 552 | memcpy(g2_array, decimalToBinary(colours[2][1]), sizeof(g2_array)); |
ivanyohuno | 0:22b6f7132818 | 553 | memcpy(b2_array, decimalToBinary(colours[2][2]), sizeof(b2_array)); |
ivanyohuno | 0:22b6f7132818 | 554 | int r3_array[8]; //LED3 |
ivanyohuno | 0:22b6f7132818 | 555 | int g3_array[8]; |
ivanyohuno | 0:22b6f7132818 | 556 | int b3_array[8]; |
ivanyohuno | 0:22b6f7132818 | 557 | memcpy(r3_array, decimalToBinary(colours[3][0]), sizeof(r3_array)); |
ivanyohuno | 0:22b6f7132818 | 558 | memcpy(g3_array, decimalToBinary(colours[3][1]), sizeof(g3_array)); |
ivanyohuno | 0:22b6f7132818 | 559 | memcpy(b3_array, decimalToBinary(colours[3][2]), sizeof(b3_array)); |
ivanyohuno | 0:22b6f7132818 | 560 | int r4_array[8]; //LED4 |
ivanyohuno | 0:22b6f7132818 | 561 | int g4_array[8]; |
ivanyohuno | 0:22b6f7132818 | 562 | int b4_array[8]; |
ivanyohuno | 0:22b6f7132818 | 563 | memcpy(r4_array, decimalToBinary(colours[4][0]), sizeof(r4_array)); |
ivanyohuno | 0:22b6f7132818 | 564 | memcpy(g4_array, decimalToBinary(colours[4][1]), sizeof(g4_array)); |
ivanyohuno | 0:22b6f7132818 | 565 | memcpy(b4_array, decimalToBinary(colours[4][2]), sizeof(b4_array)); |
ivanyohuno | 0:22b6f7132818 | 566 | int r5_array[8]; //LED5 |
ivanyohuno | 0:22b6f7132818 | 567 | int g5_array[8]; |
ivanyohuno | 0:22b6f7132818 | 568 | int b5_array[8]; |
ivanyohuno | 0:22b6f7132818 | 569 | memcpy(r5_array, decimalToBinary(colours[5][0]), sizeof(r5_array)); |
ivanyohuno | 0:22b6f7132818 | 570 | memcpy(g5_array, decimalToBinary(colours[5][1]), sizeof(g5_array)); |
ivanyohuno | 0:22b6f7132818 | 571 | memcpy(b5_array, decimalToBinary(colours[5][2]), sizeof(b5_array)); |
ivanyohuno | 0:22b6f7132818 | 572 | int r6_array[8]; //LED6 |
ivanyohuno | 0:22b6f7132818 | 573 | int g6_array[8]; |
ivanyohuno | 0:22b6f7132818 | 574 | int b6_array[8]; |
ivanyohuno | 0:22b6f7132818 | 575 | memcpy(r6_array, decimalToBinary(colours[6][0]), sizeof(r6_array)); |
ivanyohuno | 0:22b6f7132818 | 576 | memcpy(g6_array, decimalToBinary(colours[6][1]), sizeof(g6_array)); |
ivanyohuno | 0:22b6f7132818 | 577 | memcpy(b6_array, decimalToBinary(colours[6][2]), sizeof(b6_array)); |
ivanyohuno | 0:22b6f7132818 | 578 | int r7_array[8]; //LED7 |
ivanyohuno | 0:22b6f7132818 | 579 | int g7_array[8]; |
ivanyohuno | 0:22b6f7132818 | 580 | int b7_array[8]; |
ivanyohuno | 0:22b6f7132818 | 581 | memcpy(r7_array, decimalToBinary(colours[7][0]), sizeof(r7_array)); |
ivanyohuno | 0:22b6f7132818 | 582 | memcpy(g7_array, decimalToBinary(colours[7][1]), sizeof(g7_array)); |
ivanyohuno | 0:22b6f7132818 | 583 | memcpy(b7_array, decimalToBinary(colours[7][2]), sizeof(b7_array)); |
ivanyohuno | 0:22b6f7132818 | 584 | |
ivanyohuno | 0:22b6f7132818 | 585 | //send commands to LED Driver |
ivanyohuno | 0:22b6f7132818 | 586 | //initialize SPI |
ivanyohuno | 0:22b6f7132818 | 587 | spi_init(); |
ivanyohuno | 0:22b6f7132818 | 588 | //LED0 |
ivanyohuno | 0:22b6f7132818 | 589 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 590 | spi.write(g0_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 591 | spi.write(g0_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 592 | spi.write(g0_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 593 | spi.write(g0_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 594 | spi.write(g0_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 595 | spi.write(g0_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 596 | spi.write(g0_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 597 | spi.write(g0_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 598 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 599 | spi.write(r0_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 600 | spi.write(r0_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 601 | spi.write(r0_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 602 | spi.write(r0_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 603 | spi.write(r0_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 604 | spi.write(r0_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 605 | spi.write(r0_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 606 | spi.write(r0_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 607 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 608 | spi.write(b0_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 609 | spi.write(b0_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 610 | spi.write(b0_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 611 | spi.write(b0_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 612 | spi.write(b0_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 613 | spi.write(b0_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 614 | spi.write(b0_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 615 | spi.write(b0_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 616 | //LED1 |
ivanyohuno | 0:22b6f7132818 | 617 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 618 | spi.write(g1_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 619 | spi.write(g1_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 620 | spi.write(g1_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 621 | spi.write(g1_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 622 | spi.write(g1_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 623 | spi.write(g1_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 624 | spi.write(g1_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 625 | spi.write(g1_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 626 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 627 | spi.write(r1_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 628 | spi.write(r1_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 629 | spi.write(r1_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 630 | spi.write(r1_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 631 | spi.write(r1_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 632 | spi.write(r1_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 633 | spi.write(r1_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 634 | spi.write(r1_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 635 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 636 | spi.write(b1_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 637 | spi.write(b1_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 638 | spi.write(b1_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 639 | spi.write(b1_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 640 | spi.write(b1_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 641 | spi.write(b1_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 642 | spi.write(b1_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 643 | spi.write(b1_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 644 | //LED2 |
ivanyohuno | 0:22b6f7132818 | 645 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 646 | spi.write(g2_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 647 | spi.write(g2_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 648 | spi.write(g2_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 649 | spi.write(g2_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 650 | spi.write(g2_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 651 | spi.write(g2_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 652 | spi.write(g2_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 653 | spi.write(g2_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 654 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 655 | spi.write(r2_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 656 | spi.write(r2_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 657 | spi.write(r2_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 658 | spi.write(r2_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 659 | spi.write(r2_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 660 | spi.write(r2_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 661 | spi.write(r2_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 662 | spi.write(r2_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 663 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 664 | spi.write(b2_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 665 | spi.write(b2_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 666 | spi.write(b2_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 667 | spi.write(b2_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 668 | spi.write(b2_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 669 | spi.write(b2_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 670 | spi.write(b2_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 671 | spi.write(b2_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 672 | //LED3 |
ivanyohuno | 0:22b6f7132818 | 673 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 674 | spi.write(g3_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 675 | spi.write(g3_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 676 | spi.write(g3_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 677 | spi.write(g3_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 678 | spi.write(g3_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 679 | spi.write(g3_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 680 | spi.write(g3_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 681 | spi.write(g3_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 682 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 683 | spi.write(r3_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 684 | spi.write(r3_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 685 | spi.write(r3_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 686 | spi.write(r3_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 687 | spi.write(r3_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 688 | spi.write(r3_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 689 | spi.write(r3_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 690 | spi.write(r3_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 691 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 692 | spi.write(b3_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 693 | spi.write(b3_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 694 | spi.write(b3_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 695 | spi.write(b3_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 696 | spi.write(b3_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 697 | spi.write(b3_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 698 | spi.write(b3_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 699 | spi.write(b3_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 700 | //LED4 |
ivanyohuno | 0:22b6f7132818 | 701 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 702 | spi.write(g4_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 703 | spi.write(g4_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 704 | spi.write(g4_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 705 | spi.write(g4_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 706 | spi.write(g4_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 707 | spi.write(g4_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 708 | spi.write(g4_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 709 | spi.write(g4_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 710 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 711 | spi.write(r4_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 712 | spi.write(r4_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 713 | spi.write(r4_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 714 | spi.write(r4_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 715 | spi.write(r4_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 716 | spi.write(r4_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 717 | spi.write(r4_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 718 | spi.write(r4_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 719 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 720 | spi.write(b4_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 721 | spi.write(b4_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 722 | spi.write(b4_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 723 | spi.write(b4_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 724 | spi.write(b4_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 725 | spi.write(b4_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 726 | spi.write(b4_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 727 | spi.write(b4_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 728 | //LED5 |
ivanyohuno | 0:22b6f7132818 | 729 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 730 | spi.write(g5_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 731 | spi.write(g5_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 732 | spi.write(g5_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 733 | spi.write(g5_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 734 | spi.write(g5_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 735 | spi.write(g5_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 736 | spi.write(g5_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 737 | spi.write(g5_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 738 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 739 | spi.write(r5_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 740 | spi.write(r5_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 741 | spi.write(r5_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 742 | spi.write(r5_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 743 | spi.write(r5_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 744 | spi.write(r5_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 745 | spi.write(r5_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 746 | spi.write(r5_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 747 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 748 | spi.write(b5_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 749 | spi.write(b5_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 750 | spi.write(b5_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 751 | spi.write(b5_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 752 | spi.write(b5_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 753 | spi.write(b5_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 754 | spi.write(b5_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 755 | spi.write(b5_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 756 | //LED6 |
ivanyohuno | 0:22b6f7132818 | 757 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 758 | spi.write(g6_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 759 | spi.write(g6_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 760 | spi.write(g6_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 761 | spi.write(g6_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 762 | spi.write(g6_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 763 | spi.write(g6_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 764 | spi.write(g6_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 765 | spi.write(g6_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 766 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 767 | spi.write(r6_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 768 | spi.write(r6_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 769 | spi.write(r6_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 770 | spi.write(r6_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 771 | spi.write(r6_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 772 | spi.write(r6_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 773 | spi.write(r6_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 774 | spi.write(r6_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 775 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 776 | spi.write(b6_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 777 | spi.write(b6_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 778 | spi.write(b6_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 779 | spi.write(b6_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 780 | spi.write(b6_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 781 | spi.write(b6_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 782 | spi.write(b6_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 783 | spi.write(b6_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 784 | //LED7 |
ivanyohuno | 0:22b6f7132818 | 785 | //set green bits |
ivanyohuno | 0:22b6f7132818 | 786 | spi.write(g7_array[7]); //set g7 bit |
ivanyohuno | 0:22b6f7132818 | 787 | spi.write(g7_array[6]); //set g6 bit |
ivanyohuno | 0:22b6f7132818 | 788 | spi.write(g7_array[5]); //set g5 bit |
ivanyohuno | 0:22b6f7132818 | 789 | spi.write(g7_array[4]); //set g4 bit |
ivanyohuno | 0:22b6f7132818 | 790 | spi.write(g7_array[3]); //set g3 bit |
ivanyohuno | 0:22b6f7132818 | 791 | spi.write(g7_array[2]); //set g2 bit |
ivanyohuno | 0:22b6f7132818 | 792 | spi.write(g7_array[1]); //set g1 bit |
ivanyohuno | 0:22b6f7132818 | 793 | spi.write(g7_array[0]);//set g0 bit |
ivanyohuno | 0:22b6f7132818 | 794 | //set red bits |
ivanyohuno | 0:22b6f7132818 | 795 | spi.write(r7_array[7]);//set r7 bit |
ivanyohuno | 0:22b6f7132818 | 796 | spi.write(r7_array[6]); //set r6 bit |
ivanyohuno | 0:22b6f7132818 | 797 | spi.write(r7_array[5]); //set r5 bit |
ivanyohuno | 0:22b6f7132818 | 798 | spi.write(r7_array[4]); //set r4 bit |
ivanyohuno | 0:22b6f7132818 | 799 | spi.write(r7_array[3]); //set r3 bit |
ivanyohuno | 0:22b6f7132818 | 800 | spi.write(r7_array[2]); //set r2 bit |
ivanyohuno | 0:22b6f7132818 | 801 | spi.write(r7_array[1]); //set r1 bit |
ivanyohuno | 0:22b6f7132818 | 802 | spi.write(r7_array[0]); //set r0 bit |
ivanyohuno | 0:22b6f7132818 | 803 | //set blue bits |
ivanyohuno | 0:22b6f7132818 | 804 | spi.write(b7_array[7]); //set b7 bit |
ivanyohuno | 0:22b6f7132818 | 805 | spi.write(b7_array[6]); //set b6 bit |
ivanyohuno | 0:22b6f7132818 | 806 | spi.write(b7_array[5]); //set b5 bit |
ivanyohuno | 0:22b6f7132818 | 807 | spi.write(b7_array[4]); //set b4 bit |
ivanyohuno | 0:22b6f7132818 | 808 | spi.write(b7_array[3]); //set b3 bit |
ivanyohuno | 0:22b6f7132818 | 809 | spi.write(b7_array[2]); //set b2 bit |
ivanyohuno | 0:22b6f7132818 | 810 | spi.write(b7_array[1]); //set b1 bit |
ivanyohuno | 0:22b6f7132818 | 811 | spi.write(b7_array[0]); //set b0 bit |
ivanyohuno | 0:22b6f7132818 | 812 | //wait for latch |
ivanyohuno | 0:22b6f7132818 | 813 | wait_us(60); |
ivanyohuno | 0:22b6f7132818 | 814 | } |
ivanyohuno | 0:22b6f7132818 | 815 | |
ivanyohuno | 0:22b6f7132818 | 816 | void neopixels_spi::setRGBPixels2(int colours[8][3]){ |
ivanyohuno | 0:22b6f7132818 | 817 | //translate int values to array of 0xF00 (0) and 0xFF0 (1) binary |
ivanyohuno | 0:22b6f7132818 | 818 | int r0_array[8]; //LED0 |
ivanyohuno | 0:22b6f7132818 | 819 | int g0_array[8]; |
ivanyohuno | 0:22b6f7132818 | 820 | int b0_array[8]; |
ivanyohuno | 0:22b6f7132818 | 821 | memcpy(r0_array, decimalToBinary(colours[0][0]), sizeof(r0_array)); |
ivanyohuno | 0:22b6f7132818 | 822 | memcpy(g0_array, decimalToBinary(colours[0][1]), sizeof(g0_array)); |
ivanyohuno | 0:22b6f7132818 | 823 | memcpy(b0_array, decimalToBinary(colours[0][2]), sizeof(b0_array)); |
ivanyohuno | 0:22b6f7132818 | 824 | int r1_array[8]; //LED1 |
ivanyohuno | 0:22b6f7132818 | 825 | int g1_array[8]; |
ivanyohuno | 0:22b6f7132818 | 826 | int b1_array[8]; |
ivanyohuno | 0:22b6f7132818 | 827 | memcpy(r1_array, decimalToBinary(colours[1][0]), sizeof(r1_array)); |
ivanyohuno | 0:22b6f7132818 | 828 | memcpy(g1_array, decimalToBinary(colours[1][1]), sizeof(g1_array)); |
ivanyohuno | 0:22b6f7132818 | 829 | memcpy(b1_array, decimalToBinary(colours[1][2]), sizeof(b1_array)); |
ivanyohuno | 0:22b6f7132818 | 830 | int r2_array[8]; //LED2 |
ivanyohuno | 0:22b6f7132818 | 831 | int g2_array[8]; |
ivanyohuno | 0:22b6f7132818 | 832 | int b2_array[8]; |
ivanyohuno | 0:22b6f7132818 | 833 | memcpy(r2_array, decimalToBinary(colours[2][0]), sizeof(r2_array)); |
ivanyohuno | 0:22b6f7132818 | 834 | memcpy(g2_array, decimalToBinary(colours[2][1]), sizeof(g2_array)); |
ivanyohuno | 0:22b6f7132818 | 835 | memcpy(b2_array, decimalToBinary(colours[2][2]), sizeof(b2_array)); |
ivanyohuno | 0:22b6f7132818 | 836 | int r3_array[8]; //LED3 |
ivanyohuno | 0:22b6f7132818 | 837 | int g3_array[8]; |
ivanyohuno | 0:22b6f7132818 | 838 | int b3_array[8]; |
ivanyohuno | 0:22b6f7132818 | 839 | memcpy(r3_array, decimalToBinary(colours[3][0]), sizeof(r3_array)); |
ivanyohuno | 0:22b6f7132818 | 840 | memcpy(g3_array, decimalToBinary(colours[3][1]), sizeof(g3_array)); |
ivanyohuno | 0:22b6f7132818 | 841 | memcpy(b3_array, decimalToBinary(colours[3][2]), sizeof(b3_array)); |
ivanyohuno | 0:22b6f7132818 | 842 | int r4_array[8]; //LED4 |
ivanyohuno | 0:22b6f7132818 | 843 | int g4_array[8]; |
ivanyohuno | 0:22b6f7132818 | 844 | int b4_array[8]; |
ivanyohuno | 0:22b6f7132818 | 845 | memcpy(r4_array, decimalToBinary(colours[4][0]), sizeof(r4_array)); |
ivanyohuno | 0:22b6f7132818 | 846 | memcpy(g4_array, decimalToBinary(colours[4][1]), sizeof(g4_array)); |
ivanyohuno | 0:22b6f7132818 | 847 | memcpy(b4_array, decimalToBinary(colours[4][2]), sizeof(b4_array)); |
ivanyohuno | 0:22b6f7132818 | 848 | int r5_array[8]; //LED5 |
ivanyohuno | 0:22b6f7132818 | 849 | int g5_array[8]; |
ivanyohuno | 0:22b6f7132818 | 850 | int b5_array[8]; |
ivanyohuno | 0:22b6f7132818 | 851 | memcpy(r5_array, decimalToBinary(colours[5][0]), sizeof(r5_array)); |
ivanyohuno | 0:22b6f7132818 | 852 | memcpy(g5_array, decimalToBinary(colours[5][1]), sizeof(g5_array)); |
ivanyohuno | 0:22b6f7132818 | 853 | memcpy(b5_array, decimalToBinary(colours[5][2]), sizeof(b5_array)); |
ivanyohuno | 0:22b6f7132818 | 854 | int r6_array[8]; //LED6 |
ivanyohuno | 0:22b6f7132818 | 855 | int g6_array[8]; |
ivanyohuno | 0:22b6f7132818 | 856 | int b6_array[8]; |
ivanyohuno | 0:22b6f7132818 | 857 | memcpy(r6_array, decimalToBinary(colours[6][0]), sizeof(r6_array)); |
ivanyohuno | 0:22b6f7132818 | 858 | memcpy(g6_array, decimalToBinary(colours[6][1]), sizeof(g6_array)); |
ivanyohuno | 0:22b6f7132818 | 859 | memcpy(b6_array, decimalToBinary(colours[6][2]), sizeof(b6_array)); |
ivanyohuno | 0:22b6f7132818 | 860 | int r7_array[8]; //LED7 |
ivanyohuno | 0:22b6f7132818 | 861 | int g7_array[8]; |
ivanyohuno | 0:22b6f7132818 | 862 | int b7_array[8]; |
ivanyohuno | 0:22b6f7132818 | 863 | memcpy(r7_array, decimalToBinary(colours[7][0]), sizeof(r7_array)); |
ivanyohuno | 0:22b6f7132818 | 864 | memcpy(g7_array, decimalToBinary(colours[7][1]), sizeof(g7_array)); |
ivanyohuno | 0:22b6f7132818 | 865 | memcpy(b7_array, decimalToBinary(colours[7][2]), sizeof(b7_array)); |
ivanyohuno | 0:22b6f7132818 | 866 | |
ivanyohuno | 0:22b6f7132818 | 867 | //send commands to LED Driver |
ivanyohuno | 0:22b6f7132818 | 868 | //initialize SPI |
ivanyohuno | 0:22b6f7132818 | 869 | spi_init(); |
ivanyohuno | 0:22b6f7132818 | 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 |
ivanyohuno | 0:22b6f7132818 | 1095 | wait_us(60); |
ivanyohuno | 0:22b6f7132818 | 1096 | } |
ivanyohuno | 0:22b6f7132818 | 1097 | int * neopixels_spi ::decimalToBinary(int n) // converts decimal value to 8 bit array of 1's (0xFF0) and 0's (0xF00) |
ivanyohuno | 0:22b6f7132818 | 1098 | { |
ivanyohuno | 0:22b6f7132818 | 1099 | int reminder; |
ivanyohuno | 0:22b6f7132818 | 1100 | int i=0; |
ivanyohuno | 0:22b6f7132818 | 1101 | int static binary[8]; //initialize to 00000000 |
ivanyohuno | 0:22b6f7132818 | 1102 | while (n!=0) |
ivanyohuno | 0:22b6f7132818 | 1103 | { |
ivanyohuno | 0:22b6f7132818 | 1104 | reminder=n%2; |
ivanyohuno | 0:22b6f7132818 | 1105 | if(reminder == 1){ |
ivanyohuno | 0:22b6f7132818 | 1106 | binary[i] = 0xFF0; |
ivanyohuno | 0:22b6f7132818 | 1107 | } |
ivanyohuno | 0:22b6f7132818 | 1108 | if(reminder == 0){ |
ivanyohuno | 0:22b6f7132818 | 1109 | binary[i] = 0xF00; |
ivanyohuno | 0:22b6f7132818 | 1110 | } |
ivanyohuno | 0:22b6f7132818 | 1111 | n = n/2; |
ivanyohuno | 0:22b6f7132818 | 1112 | i++; |
ivanyohuno | 0:22b6f7132818 | 1113 | } |
ivanyohuno | 0:22b6f7132818 | 1114 | //sets the remainder of the digits to 0xF00 if n reaches 0 before i = 7 |
ivanyohuno | 0:22b6f7132818 | 1115 | for(;i<8;i++){ |
ivanyohuno | 0:22b6f7132818 | 1116 | binary[i] = 0xF00; |
ivanyohuno | 0:22b6f7132818 | 1117 | } |
ivanyohuno | 0:22b6f7132818 | 1118 | return binary; |
ivanyohuno | 0:22b6f7132818 | 1119 | } |
ivanyohuno | 0:22b6f7132818 | 1120 | |
ivanyohuno | 0:22b6f7132818 | 1121 | void neopixels_spi ::spi_init(){ //initializes spi port to send 0 bit length |
ivanyohuno | 0:22b6f7132818 | 1122 | spi.format(14, 0); //set spi at 14 bits/byte with clock phase and clock polarity at mode 0 |
ivanyohuno | 0:22b6f7132818 | 1123 | spi.frequency(10600000); //set frequency of spi clock at 96/9 - 10.6MHz 94.3 ns bit time length |
ivanyohuno | 0:22b6f7132818 | 1124 | spi2.format(14, 0); //set spi at 14 bits/byte with clock phase and clock polarity at mode 0 |
ivanyohuno | 0:22b6f7132818 | 1125 | spi2.frequency(10600000); //set frequency of spi clock at 96/9 - 10.6MHz 94.3 ns bit time length |
ivanyohuno | 0:22b6f7132818 | 1126 | |
ivanyohuno | 0:22b6f7132818 | 1127 | } |