Practical Robotics Modular Robot Library
led.cpp@6:732aa91eb555, 2017-01-13 (annotated)
- Committer:
- jah128
- Date:
- Fri Jan 13 23:16:23 2017 +0000
- Revision:
- 6:732aa91eb555
- Parent:
- 5:6da8daaeb9f7
Updated;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 0:8a2dd255c508 | 1 | #include "robot.h" |
jah128 | 0:8a2dd255c508 | 2 | |
jah128 | 0:8a2dd255c508 | 3 | // The LED driver is quite powerful in terms of how it can be used (LEDs can be grouped, have individual and group PWM control, can be blinked etc). |
jah128 | 0:8a2dd255c508 | 4 | // |
jah128 | 0:8a2dd255c508 | 5 | // To keep things relatively simple, in this version of the code, we will not use the groups or blinking functions, and will have all LEDs enabled. |
jah128 | 0:8a2dd255c508 | 6 | // |
jah128 | 0:8a2dd255c508 | 7 | // Their state is controlled solely by each LEDs PWM control - which is a 1 byte value between 0 (fully off) and 255 (fully on) |
jah128 | 0:8a2dd255c508 | 8 | |
jah128 | 0:8a2dd255c508 | 9 | char red_led_states [8]; |
jah128 | 0:8a2dd255c508 | 10 | char green_led_states [8]; |
jah128 | 4:c2e933d53bea | 11 | Ticker led_ticker; |
jah128 | 4:c2e933d53bea | 12 | int animation_on = 0; |
jah128 | 4:c2e933d53bea | 13 | int animation_mode = 0; |
jah128 | 4:c2e933d53bea | 14 | int animation_state = 0; |
jah128 | 4:c2e933d53bea | 15 | int animation_substate = 0; |
jah128 | 4:c2e933d53bea | 16 | char increment = 1; |
jah128 | 4:c2e933d53bea | 17 | |
jah128 | 4:c2e933d53bea | 18 | void Led::restore_states () |
jah128 | 4:c2e933d53bea | 19 | { |
jah128 | 4:c2e933d53bea | 20 | char data[17]; |
jah128 | 4:c2e933d53bea | 21 | data[0]=130; //2 + 128 (AutoInc for brightness) |
jah128 | 4:c2e933d53bea | 22 | for(int i=0; i<8; i++) { |
jah128 | 4:c2e933d53bea | 23 | data[(i+i)+1] = red_led_states[i]; |
jah128 | 4:c2e933d53bea | 24 | data[(i+i)+2] = green_led_states[i]; |
jah128 | 4:c2e933d53bea | 25 | } |
jah128 | 4:c2e933d53bea | 26 | if(animation_on == 1) stop_animation(); |
jah128 | 4:c2e933d53bea | 27 | else { |
jah128 | 4:c2e933d53bea | 28 | if(i2c_lock==0) { |
jah128 | 4:c2e933d53bea | 29 | i2c_lock = 1; |
jah128 | 4:c2e933d53bea | 30 | primary_i2c.write(LED_ADDRESS,data,17); |
jah128 | 4:c2e933d53bea | 31 | } |
jah128 | 4:c2e933d53bea | 32 | i2c_lock = 0; |
jah128 | 4:c2e933d53bea | 33 | } |
jah128 | 4:c2e933d53bea | 34 | } |
jah128 | 4:c2e933d53bea | 35 | |
jah128 | 4:c2e933d53bea | 36 | void Led::set_all (char red_brightness, char green_brightness) |
jah128 | 4:c2e933d53bea | 37 | { |
jah128 | 4:c2e933d53bea | 38 | char data[17]; |
jah128 | 4:c2e933d53bea | 39 | data[0]=130; //2 + 128 (AutoInc for brightness) |
jah128 | 4:c2e933d53bea | 40 | for(int i=0; i<8; i++) { |
jah128 | 4:c2e933d53bea | 41 | red_led_states[i] = red_brightness; |
jah128 | 4:c2e933d53bea | 42 | green_led_states[i] = green_brightness; |
jah128 | 4:c2e933d53bea | 43 | data[(i+i)+1] = red_brightness; |
jah128 | 4:c2e933d53bea | 44 | data[(i+i)+2] = green_brightness; |
jah128 | 4:c2e933d53bea | 45 | } |
jah128 | 4:c2e933d53bea | 46 | if(animation_on == 1) stop_animation(); |
jah128 | 4:c2e933d53bea | 47 | else { |
jah128 | 4:c2e933d53bea | 48 | if(i2c_lock==0) { |
jah128 | 4:c2e933d53bea | 49 | i2c_lock = 1; |
jah128 | 4:c2e933d53bea | 50 | primary_i2c.write(LED_ADDRESS,data,17); |
jah128 | 4:c2e933d53bea | 51 | } |
jah128 | 4:c2e933d53bea | 52 | i2c_lock = 0; |
jah128 | 4:c2e933d53bea | 53 | } |
jah128 | 4:c2e933d53bea | 54 | } |
jah128 | 4:c2e933d53bea | 55 | |
jah128 | 4:c2e933d53bea | 56 | void Led::set_leds (char * red_brightness, char * green_brightness) |
jah128 | 4:c2e933d53bea | 57 | { |
jah128 | 4:c2e933d53bea | 58 | char data[17]; |
jah128 | 4:c2e933d53bea | 59 | data[0]=130; //2 + 128 (AutoInc for brightness) |
jah128 | 4:c2e933d53bea | 60 | for(int i=0; i<8; i++) { |
jah128 | 4:c2e933d53bea | 61 | red_led_states[i] = red_brightness[i]; |
jah128 | 4:c2e933d53bea | 62 | green_led_states[i] = green_brightness[i]; |
jah128 | 4:c2e933d53bea | 63 | data[(i+i)+1] = red_brightness[i]; |
jah128 | 4:c2e933d53bea | 64 | data[(i+i)+2] = green_brightness[i]; |
jah128 | 4:c2e933d53bea | 65 | } |
jah128 | 4:c2e933d53bea | 66 | if(animation_on == 1) stop_animation(); |
jah128 | 4:c2e933d53bea | 67 | else { |
jah128 | 4:c2e933d53bea | 68 | if(i2c_lock==0) { |
jah128 | 4:c2e933d53bea | 69 | i2c_lock = 1; |
jah128 | 4:c2e933d53bea | 70 | primary_i2c.write(LED_ADDRESS,data,17); |
jah128 | 4:c2e933d53bea | 71 | } |
jah128 | 4:c2e933d53bea | 72 | i2c_lock = 0; |
jah128 | 4:c2e933d53bea | 73 | } |
jah128 | 4:c2e933d53bea | 74 | } |
jah128 | 4:c2e933d53bea | 75 | |
jah128 | 4:c2e933d53bea | 76 | |
jah128 | 4:c2e933d53bea | 77 | void Led::set_leds (char red1, char red2, char red3, char red4, char red5, char red6, char red7, char red8, char grn1, char grn2, char grn3, char grn4, char grn5, char grn6, char grn7, char grn8) |
jah128 | 4:c2e933d53bea | 78 | { |
jah128 | 4:c2e933d53bea | 79 | char data[17]; |
jah128 | 4:c2e933d53bea | 80 | data[0]=130; //2 + 128 (AutoInc for brightness) |
jah128 | 4:c2e933d53bea | 81 | red_led_states[0] = red1; |
jah128 | 4:c2e933d53bea | 82 | red_led_states[1] = red2; |
jah128 | 4:c2e933d53bea | 83 | red_led_states[2] = red3; |
jah128 | 4:c2e933d53bea | 84 | red_led_states[3] = red4; |
jah128 | 4:c2e933d53bea | 85 | red_led_states[4] = red5; |
jah128 | 4:c2e933d53bea | 86 | red_led_states[5] = red6; |
jah128 | 4:c2e933d53bea | 87 | red_led_states[6] = red7; |
jah128 | 4:c2e933d53bea | 88 | red_led_states[7] = red8; |
jah128 | 4:c2e933d53bea | 89 | green_led_states[0] = grn1; |
jah128 | 4:c2e933d53bea | 90 | green_led_states[1] = grn2; |
jah128 | 4:c2e933d53bea | 91 | green_led_states[2] = grn3; |
jah128 | 4:c2e933d53bea | 92 | green_led_states[3] = grn4; |
jah128 | 4:c2e933d53bea | 93 | green_led_states[4] = grn5; |
jah128 | 4:c2e933d53bea | 94 | green_led_states[5] = grn6; |
jah128 | 4:c2e933d53bea | 95 | green_led_states[6] = grn7; |
jah128 | 4:c2e933d53bea | 96 | green_led_states[7] = grn8; |
jah128 | 4:c2e933d53bea | 97 | for(int i=0; i<8; i++) { |
jah128 | 4:c2e933d53bea | 98 | data[(i+i)+1] = red_led_states[i]; |
jah128 | 4:c2e933d53bea | 99 | data[(i+i)+2] = green_led_states[i]; |
jah128 | 4:c2e933d53bea | 100 | } |
jah128 | 4:c2e933d53bea | 101 | if(animation_on == 1) stop_animation(); |
jah128 | 4:c2e933d53bea | 102 | else { |
jah128 | 4:c2e933d53bea | 103 | if(i2c_lock==0) { |
jah128 | 4:c2e933d53bea | 104 | i2c_lock = 1; |
jah128 | 4:c2e933d53bea | 105 | primary_i2c.write(LED_ADDRESS,data,17); |
jah128 | 4:c2e933d53bea | 106 | } |
jah128 | 4:c2e933d53bea | 107 | i2c_lock = 0; |
jah128 | 4:c2e933d53bea | 108 | } |
jah128 | 4:c2e933d53bea | 109 | } |
jah128 | 4:c2e933d53bea | 110 | |
jah128 | 4:c2e933d53bea | 111 | void Led::_set_leds (char red1, char red2, char red3, char red4, char red5, char red6, char red7, char red8, char grn1, char grn2, char grn3, char grn4, char grn5, char grn6, char grn7, char grn8) |
jah128 | 4:c2e933d53bea | 112 | { |
jah128 | 4:c2e933d53bea | 113 | char data[17]; |
jah128 | 4:c2e933d53bea | 114 | data[0]=130; //2 + 128 (AutoInc for brightness) |
jah128 | 4:c2e933d53bea | 115 | data[1] = red1; |
jah128 | 4:c2e933d53bea | 116 | data[3] = red2; |
jah128 | 4:c2e933d53bea | 117 | data[5] = red3; |
jah128 | 4:c2e933d53bea | 118 | data[7] = red4; |
jah128 | 4:c2e933d53bea | 119 | data[9] = red5; |
jah128 | 4:c2e933d53bea | 120 | data[11] = red6; |
jah128 | 4:c2e933d53bea | 121 | data[13] = red7; |
jah128 | 4:c2e933d53bea | 122 | data[15] = red8; |
jah128 | 4:c2e933d53bea | 123 | data[2] = grn1; |
jah128 | 4:c2e933d53bea | 124 | data[4] = grn2; |
jah128 | 4:c2e933d53bea | 125 | data[6] = grn3; |
jah128 | 4:c2e933d53bea | 126 | data[8] = grn4; |
jah128 | 4:c2e933d53bea | 127 | data[10] = grn5; |
jah128 | 4:c2e933d53bea | 128 | data[12] = grn6; |
jah128 | 4:c2e933d53bea | 129 | data[14] = grn7; |
jah128 | 4:c2e933d53bea | 130 | data[16] = grn8; |
jah128 | 4:c2e933d53bea | 131 | if(i2c_lock==0) { |
jah128 | 4:c2e933d53bea | 132 | i2c_lock = 1; |
jah128 | 4:c2e933d53bea | 133 | primary_i2c.write(LED_ADDRESS,data,17); |
jah128 | 4:c2e933d53bea | 134 | } |
jah128 | 4:c2e933d53bea | 135 | i2c_lock = 0; |
jah128 | 4:c2e933d53bea | 136 | |
jah128 | 4:c2e933d53bea | 137 | } |
jah128 | 0:8a2dd255c508 | 138 | |
jah128 | 3:8762f6b2ea8d | 139 | void Led::all_off() |
jah128 | 3:8762f6b2ea8d | 140 | { |
jah128 | 4:c2e933d53bea | 141 | char data[17]; |
jah128 | 4:c2e933d53bea | 142 | data[0]=130; //2 + 128 (AutoInc for brightness) |
jah128 | 4:c2e933d53bea | 143 | for(int i=0; i<8; i++) { |
jah128 | 4:c2e933d53bea | 144 | red_led_states[i] = 0; |
jah128 | 4:c2e933d53bea | 145 | green_led_states[i] = 0; |
jah128 | 4:c2e933d53bea | 146 | data[(i+i)+1] = 0; |
jah128 | 4:c2e933d53bea | 147 | data[(i+i)+2] = 0; |
jah128 | 4:c2e933d53bea | 148 | } |
jah128 | 4:c2e933d53bea | 149 | if(animation_on == 1) stop_animation(); |
jah128 | 4:c2e933d53bea | 150 | else { |
jah128 | 4:c2e933d53bea | 151 | if(i2c_lock==0) { |
jah128 | 4:c2e933d53bea | 152 | i2c_lock = 1; |
jah128 | 4:c2e933d53bea | 153 | primary_i2c.write(LED_ADDRESS,data,17); |
jah128 | 4:c2e933d53bea | 154 | } |
jah128 | 4:c2e933d53bea | 155 | i2c_lock = 0; |
jah128 | 4:c2e933d53bea | 156 | } |
jah128 | 3:8762f6b2ea8d | 157 | } |
jah128 | 3:8762f6b2ea8d | 158 | |
jah128 | 4:c2e933d53bea | 159 | |
jah128 | 4:c2e933d53bea | 160 | |
jah128 | 0:8a2dd255c508 | 161 | void Led::set_green_led (char led, char brightness) |
jah128 | 0:8a2dd255c508 | 162 | { |
jah128 | 0:8a2dd255c508 | 163 | if(led < 8) { |
jah128 | 0:8a2dd255c508 | 164 | green_led_states [led] = brightness; |
jah128 | 0:8a2dd255c508 | 165 | char data[2]; |
jah128 | 0:8a2dd255c508 | 166 | data[0] = 3 + led + led; |
jah128 | 0:8a2dd255c508 | 167 | data[1] = brightness; |
jah128 | 4:c2e933d53bea | 168 | if(animation_on == 1) stop_animation(); |
jah128 | 4:c2e933d53bea | 169 | else { |
jah128 | 4:c2e933d53bea | 170 | if(i2c_lock==0) { |
jah128 | 4:c2e933d53bea | 171 | i2c_lock = 1; |
jah128 | 4:c2e933d53bea | 172 | primary_i2c.write(LED_ADDRESS,data,2); |
jah128 | 4:c2e933d53bea | 173 | } |
jah128 | 4:c2e933d53bea | 174 | i2c_lock = 0; |
jah128 | 4:c2e933d53bea | 175 | } |
jah128 | 0:8a2dd255c508 | 176 | } |
jah128 | 0:8a2dd255c508 | 177 | } |
jah128 | 0:8a2dd255c508 | 178 | |
jah128 | 0:8a2dd255c508 | 179 | void Led::set_red_led (char led, char brightness) |
jah128 | 0:8a2dd255c508 | 180 | { |
jah128 | 0:8a2dd255c508 | 181 | if(led < 8) { |
jah128 | 0:8a2dd255c508 | 182 | red_led_states [led] = brightness; |
jah128 | 0:8a2dd255c508 | 183 | char data[2]; |
jah128 | 0:8a2dd255c508 | 184 | data[0] = 2 + led + led; |
jah128 | 0:8a2dd255c508 | 185 | data[1] = brightness; |
jah128 | 4:c2e933d53bea | 186 | if(animation_on == 1) stop_animation(); |
jah128 | 4:c2e933d53bea | 187 | else { |
jah128 | 4:c2e933d53bea | 188 | if(i2c_lock==0) { |
jah128 | 4:c2e933d53bea | 189 | i2c_lock = 1; |
jah128 | 4:c2e933d53bea | 190 | primary_i2c.write(LED_ADDRESS,data,2); |
jah128 | 4:c2e933d53bea | 191 | } |
jah128 | 4:c2e933d53bea | 192 | i2c_lock = 0; |
jah128 | 4:c2e933d53bea | 193 | } |
jah128 | 4:c2e933d53bea | 194 | } |
jah128 | 4:c2e933d53bea | 195 | } |
jah128 | 4:c2e933d53bea | 196 | |
jah128 | 4:c2e933d53bea | 197 | |
jah128 | 4:c2e933d53bea | 198 | void Led::_set_all (char red_brightness, char green_brightness) |
jah128 | 4:c2e933d53bea | 199 | { |
jah128 | 4:c2e933d53bea | 200 | char data[17]; |
jah128 | 4:c2e933d53bea | 201 | data[0]=130; //2 + 128 (AutoInc for brightness) |
jah128 | 4:c2e933d53bea | 202 | for(int i=0; i<8; i++) { |
jah128 | 4:c2e933d53bea | 203 | data[(i+i)+1] = red_brightness; |
jah128 | 4:c2e933d53bea | 204 | data[(i+i)+2] = green_brightness; |
jah128 | 4:c2e933d53bea | 205 | } |
jah128 | 4:c2e933d53bea | 206 | if(i2c_lock==0) { |
jah128 | 0:8a2dd255c508 | 207 | i2c_lock = 1; |
jah128 | 4:c2e933d53bea | 208 | primary_i2c.write(LED_ADDRESS,data,17); |
jah128 | 4:c2e933d53bea | 209 | } |
jah128 | 4:c2e933d53bea | 210 | i2c_lock = 0; |
jah128 | 4:c2e933d53bea | 211 | } |
jah128 | 4:c2e933d53bea | 212 | |
jah128 | 4:c2e933d53bea | 213 | void Led::_set_green_led (char led, char brightness) |
jah128 | 4:c2e933d53bea | 214 | { |
jah128 | 4:c2e933d53bea | 215 | if(led < 8) { |
jah128 | 4:c2e933d53bea | 216 | char data[2]; |
jah128 | 4:c2e933d53bea | 217 | data[0] = 3 + led + led; |
jah128 | 4:c2e933d53bea | 218 | data[1] = brightness; |
jah128 | 4:c2e933d53bea | 219 | if(i2c_lock==0) { |
jah128 | 4:c2e933d53bea | 220 | i2c_lock = 1; |
jah128 | 4:c2e933d53bea | 221 | primary_i2c.write(LED_ADDRESS,data,2); |
jah128 | 4:c2e933d53bea | 222 | } |
jah128 | 4:c2e933d53bea | 223 | i2c_lock = 0; |
jah128 | 4:c2e933d53bea | 224 | } |
jah128 | 4:c2e933d53bea | 225 | } |
jah128 | 4:c2e933d53bea | 226 | |
jah128 | 4:c2e933d53bea | 227 | void Led::_set_red_led (char led, char brightness) |
jah128 | 4:c2e933d53bea | 228 | { |
jah128 | 4:c2e933d53bea | 229 | |
jah128 | 4:c2e933d53bea | 230 | if(led < 8) { |
jah128 | 4:c2e933d53bea | 231 | char data[2]; |
jah128 | 4:c2e933d53bea | 232 | data[0] = 2 + led + led; |
jah128 | 4:c2e933d53bea | 233 | data[1] = brightness; |
jah128 | 4:c2e933d53bea | 234 | if(i2c_lock==0) { |
jah128 | 4:c2e933d53bea | 235 | i2c_lock = 1; |
jah128 | 4:c2e933d53bea | 236 | primary_i2c.write(LED_ADDRESS,data,2); |
jah128 | 4:c2e933d53bea | 237 | } |
jah128 | 4:c2e933d53bea | 238 | i2c_lock = 0; |
jah128 | 4:c2e933d53bea | 239 | } |
jah128 | 4:c2e933d53bea | 240 | } |
jah128 | 4:c2e933d53bea | 241 | |
jah128 | 4:c2e933d53bea | 242 | void Led::_set_leds (char * red_brightness, char * green_brightness) |
jah128 | 4:c2e933d53bea | 243 | { |
jah128 | 4:c2e933d53bea | 244 | char data[17]; |
jah128 | 4:c2e933d53bea | 245 | data[0]=130; //2 + 128 (AutoInc for brightness) |
jah128 | 4:c2e933d53bea | 246 | for(int i=0; i<8; i++) { |
jah128 | 4:c2e933d53bea | 247 | data[(i+i)+1] = red_brightness[i]; |
jah128 | 4:c2e933d53bea | 248 | data[(i+i)+2] = green_brightness[i]; |
jah128 | 4:c2e933d53bea | 249 | } |
jah128 | 4:c2e933d53bea | 250 | if(i2c_lock==0) { |
jah128 | 4:c2e933d53bea | 251 | i2c_lock = 1; |
jah128 | 4:c2e933d53bea | 252 | primary_i2c.write(LED_ADDRESS,data,17); |
jah128 | 4:c2e933d53bea | 253 | } |
jah128 | 4:c2e933d53bea | 254 | i2c_lock = 0; |
jah128 | 4:c2e933d53bea | 255 | } |
jah128 | 4:c2e933d53bea | 256 | |
jah128 | 4:c2e933d53bea | 257 | void Led::set_green_led_stored_state (char led, char brightness) |
jah128 | 4:c2e933d53bea | 258 | { |
jah128 | 4:c2e933d53bea | 259 | if(led < 8) { |
jah128 | 4:c2e933d53bea | 260 | green_led_states [led] = brightness; |
jah128 | 4:c2e933d53bea | 261 | } |
jah128 | 4:c2e933d53bea | 262 | } |
jah128 | 4:c2e933d53bea | 263 | |
jah128 | 4:c2e933d53bea | 264 | void Led::set_red_led_stored_state (char led, char brightness) |
jah128 | 4:c2e933d53bea | 265 | { |
jah128 | 4:c2e933d53bea | 266 | if(led < 8) { |
jah128 | 4:c2e933d53bea | 267 | red_led_states [led] = brightness; |
jah128 | 0:8a2dd255c508 | 268 | } |
jah128 | 0:8a2dd255c508 | 269 | } |
jah128 | 0:8a2dd255c508 | 270 | |
jah128 | 0:8a2dd255c508 | 271 | int Led::reset_led_driver() |
jah128 | 0:8a2dd255c508 | 272 | { |
jah128 | 0:8a2dd255c508 | 273 | // The TLC59116 has a software reset option over i2c: |
jah128 | 0:8a2dd255c508 | 274 | // The bytes A5h, 5Ah are sent to special address D6h |
jah128 | 0:8a2dd255c508 | 275 | char data[2]; |
jah128 | 0:8a2dd255c508 | 276 | data[0] = 0xA5; |
jah128 | 0:8a2dd255c508 | 277 | data[1] = 0x5A; |
jah128 | 0:8a2dd255c508 | 278 | return primary_i2c.write(0xD6,data,2); |
jah128 | 0:8a2dd255c508 | 279 | } |
jah128 | 0:8a2dd255c508 | 280 | |
jah128 | 0:8a2dd255c508 | 281 | int Led::init_led_driver() |
jah128 | 0:8a2dd255c508 | 282 | { |
jah128 | 0:8a2dd255c508 | 283 | // This code enables the LED outputs so all LEDs are on, and are set to work on individual PWM control |
jah128 | 0:8a2dd255c508 | 284 | // |
jah128 | 0:8a2dd255c508 | 285 | // First we write 0x80 to the Mode 1 register (0x00) to enable the oscillator and register auto-increment |
jah128 | 0:8a2dd255c508 | 286 | char data[2]; |
jah128 | 0:8a2dd255c508 | 287 | data[0]=0x00; |
jah128 | 0:8a2dd255c508 | 288 | data[1]=0x80; |
jah128 | 0:8a2dd255c508 | 289 | int okay = primary_i2c.write(LED_ADDRESS,data,2,false); |
jah128 | 0:8a2dd255c508 | 290 | if(okay == 0) { |
jah128 | 0:8a2dd255c508 | 291 | // Now we turn all the LEDs the enable on PWM control |
jah128 | 0:8a2dd255c508 | 292 | data[0]=0x14; |
jah128 | 0:8a2dd255c508 | 293 | data[1]=0xAA; |
jah128 | 0:8a2dd255c508 | 294 | primary_i2c.write(LED_ADDRESS,data,2,false); |
jah128 | 0:8a2dd255c508 | 295 | data[0]=0x15; |
jah128 | 0:8a2dd255c508 | 296 | data[1]=0xAA; |
jah128 | 0:8a2dd255c508 | 297 | primary_i2c.write(LED_ADDRESS,data,2,false); |
jah128 | 0:8a2dd255c508 | 298 | data[0]=0x16; |
jah128 | 0:8a2dd255c508 | 299 | data[1]=0xAA; |
jah128 | 0:8a2dd255c508 | 300 | primary_i2c.write(LED_ADDRESS,data,2,false); |
jah128 | 0:8a2dd255c508 | 301 | data[0]=0x17; |
jah128 | 0:8a2dd255c508 | 302 | data[1]=0xAA; |
jah128 | 0:8a2dd255c508 | 303 | primary_i2c.write(LED_ADDRESS,data,2,false); |
jah128 | 0:8a2dd255c508 | 304 | } |
jah128 | 0:8a2dd255c508 | 305 | return okay; |
jah128 | 0:8a2dd255c508 | 306 | } |
jah128 | 0:8a2dd255c508 | 307 | |
jah128 | 4:c2e933d53bea | 308 | |
jah128 | 4:c2e933d53bea | 309 | |
jah128 | 4:c2e933d53bea | 310 | //Animations |
jah128 | 4:c2e933d53bea | 311 | |
jah128 | 0:8a2dd255c508 | 312 | |
jah128 | 4:c2e933d53bea | 313 | void Led::stop_animation() |
jah128 | 0:8a2dd255c508 | 314 | { |
jah128 | 4:c2e933d53bea | 315 | if(animation_on == 1) { |
jah128 | 4:c2e933d53bea | 316 | animation_on = 0; |
jah128 | 4:c2e933d53bea | 317 | led_ticker.detach(); |
jah128 | 4:c2e933d53bea | 318 | restore_states(); |
jah128 | 4:c2e933d53bea | 319 | } |
jah128 | 0:8a2dd255c508 | 320 | } |
jah128 | 0:8a2dd255c508 | 321 | |
jah128 | 4:c2e933d53bea | 322 | void Led::start_animation(char mode, char speed) |
jah128 | 3:8762f6b2ea8d | 323 | { |
jah128 | 4:c2e933d53bea | 324 | //Speed is ranged so 0 is fastest |
jah128 | 4:c2e933d53bea | 325 | int us_delay = 4000 + (speed * 1000); |
jah128 | 4:c2e933d53bea | 326 | animation_on = 1; |
jah128 | 4:c2e933d53bea | 327 | animation_mode = mode; |
jah128 | 4:c2e933d53bea | 328 | animation_state = 0; |
jah128 | 4:c2e933d53bea | 329 | animation_substate = 0; |
jah128 | 4:c2e933d53bea | 330 | increment = 1; |
jah128 | 4:c2e933d53bea | 331 | //Turn off all LEDs |
jah128 | 4:c2e933d53bea | 332 | _set_all(0,0); |
jah128 | 4:c2e933d53bea | 333 | led_ticker.attach_us(this,&Led::animation_cycle,us_delay); |
jah128 | 3:8762f6b2ea8d | 334 | } |
jah128 | 3:8762f6b2ea8d | 335 | |
jah128 | 4:c2e933d53bea | 336 | void Led::animation_cycle() |
jah128 | 0:8a2dd255c508 | 337 | { |
jah128 | 4:c2e933d53bea | 338 | char red_brightness; |
jah128 | 4:c2e933d53bea | 339 | char green_brightness; |
jah128 | 4:c2e933d53bea | 340 | char working_led; |
jah128 | 4:c2e933d53bea | 341 | |
jah128 | 4:c2e933d53bea | 342 | switch(animation_mode) { |
jah128 | 4:c2e933d53bea | 343 | case 0: |
jah128 | 4:c2e933d53bea | 344 | // Flood-fade (boot-up animation) |
jah128 | 4:c2e933d53bea | 345 | animation_substate += increment; |
jah128 | 4:c2e933d53bea | 346 | increment += 1; |
jah128 | 4:c2e933d53bea | 347 | if(animation_substate > 250) { |
jah128 | 4:c2e933d53bea | 348 | animation_substate = 0; |
jah128 | 4:c2e933d53bea | 349 | animation_state ++; |
jah128 | 4:c2e933d53bea | 350 | increment = 1; |
jah128 | 4:c2e933d53bea | 351 | if (animation_state == 24) animation_state = 0; |
jah128 | 4:c2e933d53bea | 352 | } |
jah128 | 4:c2e933d53bea | 353 | working_led = animation_state % 8; |
jah128 | 4:c2e933d53bea | 354 | if(animation_state < 8 || animation_state > 15) _set_green_led(working_led, animation_substate ); |
jah128 | 4:c2e933d53bea | 355 | else _set_green_led(working_led, 0); |
jah128 | 4:c2e933d53bea | 356 | if(animation_state > 7) _set_red_led(working_led, animation_substate ); |
jah128 | 4:c2e933d53bea | 357 | else _set_red_led(working_led, 0); |
jah128 | 4:c2e933d53bea | 358 | break; |
jah128 | 4:c2e933d53bea | 359 | case 1: |
jah128 | 4:c2e933d53bea | 360 | // R-O-G Colour sweep |
jah128 | 4:c2e933d53bea | 361 | switch(animation_state) { |
jah128 | 4:c2e933d53bea | 362 | case 0: |
jah128 | 4:c2e933d53bea | 363 | red_brightness = 255; |
jah128 | 4:c2e933d53bea | 364 | green_brightness = animation_substate * 4; |
jah128 | 4:c2e933d53bea | 365 | break; |
jah128 | 4:c2e933d53bea | 366 | case 1: |
jah128 | 4:c2e933d53bea | 367 | red_brightness = 255 - (animation_substate * 4); |
jah128 | 4:c2e933d53bea | 368 | green_brightness = 128 + (animation_substate * 4); |
jah128 | 4:c2e933d53bea | 369 | break; |
jah128 | 4:c2e933d53bea | 370 | case 2: |
jah128 | 4:c2e933d53bea | 371 | green_brightness = 255; |
jah128 | 4:c2e933d53bea | 372 | red_brightness = 128 - (animation_substate * 4); |
jah128 | 4:c2e933d53bea | 373 | break; |
jah128 | 4:c2e933d53bea | 374 | case 3: |
jah128 | 4:c2e933d53bea | 375 | green_brightness = 255 - (animation_substate * 4); |
jah128 | 4:c2e933d53bea | 376 | red_brightness = animation_substate * 4; |
jah128 | 4:c2e933d53bea | 377 | break; |
jah128 | 4:c2e933d53bea | 378 | case 4: |
jah128 | 4:c2e933d53bea | 379 | green_brightness = 128 - (animation_substate * 4); |
jah128 | 4:c2e933d53bea | 380 | red_brightness = 128 + (animation_substate * 4); |
jah128 | 4:c2e933d53bea | 381 | break; |
jah128 | 4:c2e933d53bea | 382 | } |
jah128 | 4:c2e933d53bea | 383 | animation_substate ++; |
jah128 | 4:c2e933d53bea | 384 | if(animation_substate == 32) { |
jah128 | 4:c2e933d53bea | 385 | animation_substate = 0; |
jah128 | 4:c2e933d53bea | 386 | animation_state ++; |
jah128 | 4:c2e933d53bea | 387 | if(animation_state == 5) animation_state = 0; |
jah128 | 4:c2e933d53bea | 388 | } |
jah128 | 4:c2e933d53bea | 389 | _set_all(red_brightness,green_brightness); |
jah128 | 4:c2e933d53bea | 390 | break; |
jah128 | 4:c2e933d53bea | 391 | case 2: |
jah128 | 4:c2e933d53bea | 392 | // Red Strobe |
jah128 | 4:c2e933d53bea | 393 | if(animation_state < 6) _set_all(animation_state * 48, 0); |
jah128 | 4:c2e933d53bea | 394 | if(animation_state == 6) _set_all(255,0); |
jah128 | 4:c2e933d53bea | 395 | if(animation_state == 12) _set_all(0,0); |
jah128 | 4:c2e933d53bea | 396 | animation_state ++; |
jah128 | 4:c2e933d53bea | 397 | if(animation_state == 18) animation_state = 0; |
jah128 | 4:c2e933d53bea | 398 | break; |
jah128 | 4:c2e933d53bea | 399 | case 3: |
jah128 | 4:c2e933d53bea | 400 | // Green Strobe |
jah128 | 4:c2e933d53bea | 401 | if(animation_state < 6) _set_all(0,animation_state * 48); |
jah128 | 4:c2e933d53bea | 402 | if(animation_state == 6) _set_all(0,255); |
jah128 | 4:c2e933d53bea | 403 | if(animation_state == 12) _set_all(0,0); |
jah128 | 4:c2e933d53bea | 404 | animation_state ++; |
jah128 | 4:c2e933d53bea | 405 | if(animation_state == 18) animation_state = 0; |
jah128 | 4:c2e933d53bea | 406 | break; |
jah128 | 4:c2e933d53bea | 407 | case 4: |
jah128 | 4:c2e933d53bea | 408 | // Orange Strobe |
jah128 | 4:c2e933d53bea | 409 | if(animation_state < 6) _set_all(animation_state * 48,animation_state * 48); |
jah128 | 4:c2e933d53bea | 410 | if(animation_state == 6) _set_all(255,255); |
jah128 | 4:c2e933d53bea | 411 | if(animation_state == 12) _set_all(0,0); |
jah128 | 4:c2e933d53bea | 412 | animation_state ++; |
jah128 | 4:c2e933d53bea | 413 | if(animation_state == 18) animation_state = 0; |
jah128 | 4:c2e933d53bea | 414 | break; |
jah128 | 4:c2e933d53bea | 415 | case 5: |
jah128 | 4:c2e933d53bea | 416 | // R:G Strobe |
jah128 | 4:c2e933d53bea | 417 | if(animation_state == 0) _set_all(0,64); |
jah128 | 4:c2e933d53bea | 418 | if(animation_state == 1) _set_all(0,128); |
jah128 | 4:c2e933d53bea | 419 | if(animation_state == 2) _set_all(0,192); |
jah128 | 4:c2e933d53bea | 420 | if(animation_state == 3) _set_all(0,255); |
jah128 | 4:c2e933d53bea | 421 | if(animation_state == 7) _set_all(32,64); |
jah128 | 4:c2e933d53bea | 422 | if(animation_state == 8) _set_all(64,0); |
jah128 | 4:c2e933d53bea | 423 | if(animation_state == 9) _set_all(128,0); |
jah128 | 4:c2e933d53bea | 424 | if(animation_state == 10) _set_all(192,0); |
jah128 | 4:c2e933d53bea | 425 | if(animation_state == 11) _set_all(255,0); |
jah128 | 4:c2e933d53bea | 426 | if(animation_state == 15) _set_all(64,32); |
jah128 | 4:c2e933d53bea | 427 | animation_state ++; |
jah128 | 4:c2e933d53bea | 428 | if(animation_state == 16) animation_state = 0; |
jah128 | 4:c2e933d53bea | 429 | break; |
jah128 | 4:c2e933d53bea | 430 | case 6: |
jah128 | 4:c2e933d53bea | 431 | // Forward red chase |
jah128 | 4:c2e933d53bea | 432 | if(animation_state == 0) _set_leds( 0, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 433 | if(animation_state == 1) _set_leds( 0, 0, 64,128,128, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 434 | if(animation_state == 2) _set_leds( 0, 64,128,255,255,128, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 435 | if(animation_state == 3) _set_leds( 64,128,255,255,255,255,128, 64, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 436 | if(animation_state == 4) _set_leds(128,255,255,128,128,255,255,128, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 437 | if(animation_state == 5) _set_leds(255,255,128, 64, 64,128,255,255, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 438 | if(animation_state == 6) _set_leds(255,220, 92, 32, 32, 92,220,255, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 439 | if(animation_state == 8) _set_leds(255,192, 64, 16, 16, 64,192,255, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 440 | if(animation_state == 10) _set_leds(255,160, 32, 8, 8, 32,160,255, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 441 | if(animation_state == 12) _set_leds(255,128, 16, 0, 0, 16,128,255, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 442 | if(animation_state == 13) _set_leds(255, 64, 4, 0, 0, 4, 64,255, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 443 | if(animation_state == 14) _set_leds(255, 0, 0, 0, 0, 0, 0,255, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 444 | animation_state ++; |
jah128 | 4:c2e933d53bea | 445 | if(animation_state == 16)animation_state = 0; |
jah128 | 4:c2e933d53bea | 446 | break; |
jah128 | 4:c2e933d53bea | 447 | case 7: |
jah128 | 4:c2e933d53bea | 448 | // Reverse red chase |
jah128 | 4:c2e933d53bea | 449 | if(animation_state == 0) _set_leds( 64, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 450 | if(animation_state == 1) _set_leds(128, 64, 0, 0, 0, 0, 64,128, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 451 | if(animation_state == 2) _set_leds(255,128, 64, 0, 0, 64,128,255, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 452 | if(animation_state == 3) _set_leds(255,255,128, 64, 64,128,255,255, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 453 | if(animation_state == 4) _set_leds(128,255,255,128,128,255,255,128, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 454 | if(animation_state == 5) _set_leds( 64,128,255,255,255,255,128, 64, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 455 | if(animation_state == 6) _set_leds( 32, 92,220,255,255,220, 92, 32, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 456 | if(animation_state == 8) _set_leds( 16, 64,192,255,255,192, 64, 16, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 457 | if(animation_state == 10) _set_leds( 8, 32,160,255,255,160, 32, 8, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 458 | if(animation_state == 12) _set_leds( 0, 16,128,255,255,128, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 459 | if(animation_state == 13) _set_leds( 0, 4, 64,255,255, 64, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 460 | if(animation_state == 14) _set_leds( 0, 0, 0,255,255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 461 | animation_state ++; |
jah128 | 4:c2e933d53bea | 462 | if(animation_state == 16)animation_state = 0; |
jah128 | 4:c2e933d53bea | 463 | break; |
jah128 | 4:c2e933d53bea | 464 | case 8: |
jah128 | 4:c2e933d53bea | 465 | // Forward green chase |
jah128 | 4:c2e933d53bea | 466 | if(animation_state == 0) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 64, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 467 | if(animation_state == 1) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64,128,128, 64, 0, 0); |
jah128 | 4:c2e933d53bea | 468 | if(animation_state == 2) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0, 0, 64,128,255,255,128, 64, 0); |
jah128 | 4:c2e933d53bea | 469 | if(animation_state == 3) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0, 64,128,255,255,255,255,128, 64); |
jah128 | 4:c2e933d53bea | 470 | if(animation_state == 4) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0,128,255,255,128,128,255,255,128); |
jah128 | 4:c2e933d53bea | 471 | if(animation_state == 5) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0,255,255,128, 64, 64,128,255,255); |
jah128 | 4:c2e933d53bea | 472 | if(animation_state == 6) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0,255,220, 92, 32, 32, 92,220,255); |
jah128 | 4:c2e933d53bea | 473 | if(animation_state == 8) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0,255,192, 64, 16, 16, 64,192,255); |
jah128 | 4:c2e933d53bea | 474 | if(animation_state == 10) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0,255,160, 32, 8, 8, 32,160,255); |
jah128 | 4:c2e933d53bea | 475 | if(animation_state == 12) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0,255,128, 16, 0, 0, 16,128,255); |
jah128 | 4:c2e933d53bea | 476 | if(animation_state == 13) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0,255, 64, 4, 0, 0, 4, 64,255); |
jah128 | 4:c2e933d53bea | 477 | if(animation_state == 14) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0,255, 0, 0, 0, 0, 0, 0,255); |
jah128 | 4:c2e933d53bea | 478 | animation_state ++; |
jah128 | 4:c2e933d53bea | 479 | if(animation_state == 16)animation_state = 0; |
jah128 | 4:c2e933d53bea | 480 | break; |
jah128 | 4:c2e933d53bea | 481 | case 9: |
jah128 | 4:c2e933d53bea | 482 | // Reverse green chase |
jah128 | 4:c2e933d53bea | 483 | if(animation_state == 0) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 64); |
jah128 | 4:c2e933d53bea | 484 | if(animation_state == 1) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0,128, 64, 0, 0, 0, 0, 64,128); |
jah128 | 4:c2e933d53bea | 485 | if(animation_state == 2) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0,255,128, 64, 0, 0, 64,128,255); |
jah128 | 4:c2e933d53bea | 486 | if(animation_state == 3) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0,255,255,128, 64, 64,128,255,255); |
jah128 | 4:c2e933d53bea | 487 | if(animation_state == 4) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0,128,255,255,128,128,255,255,128); |
jah128 | 4:c2e933d53bea | 488 | if(animation_state == 5) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0, 64,128,255,255,255,255,128, 64); |
jah128 | 4:c2e933d53bea | 489 | if(animation_state == 6) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0, 32, 92,220,255,255,220, 92, 32); |
jah128 | 4:c2e933d53bea | 490 | if(animation_state == 8) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0, 16, 64,192,255,255,192, 64, 16); |
jah128 | 4:c2e933d53bea | 491 | if(animation_state == 10) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0, 8, 32,160,255,255,160, 32, 8); |
jah128 | 4:c2e933d53bea | 492 | if(animation_state == 12) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0, 0, 16,128,255,255,128, 16, 0); |
jah128 | 4:c2e933d53bea | 493 | if(animation_state == 13) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 64,255,255, 64, 4, 0); |
jah128 | 4:c2e933d53bea | 494 | if(animation_state == 14) _set_leds( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,255,255, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 495 | animation_state ++; |
jah128 | 4:c2e933d53bea | 496 | if(animation_state == 16)animation_state = 0; |
jah128 | 4:c2e933d53bea | 497 | break; |
jah128 | 4:c2e933d53bea | 498 | case 10: |
jah128 | 4:c2e933d53bea | 499 | // Forward orange chase |
jah128 | 4:c2e933d53bea | 500 | if(animation_state == 0) _set_leds( 0, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 64, 64, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 501 | if(animation_state == 1) _set_leds( 0, 0, 64,128,128, 64, 0, 0, 0, 0, 64,128,128, 64, 0, 0); |
jah128 | 4:c2e933d53bea | 502 | if(animation_state == 2) _set_leds( 0, 64,128,255,255,128, 64, 0, 0, 64,128,255,255,128, 64, 0); |
jah128 | 4:c2e933d53bea | 503 | if(animation_state == 3) _set_leds( 64,128,255,255,255,255,128, 64, 64,128,255,255,255,255,128, 64); |
jah128 | 4:c2e933d53bea | 504 | if(animation_state == 4) _set_leds(128,255,255,128,128,255,255,128,128,255,255,128,128,255,255,128); |
jah128 | 4:c2e933d53bea | 505 | if(animation_state == 5) _set_leds(255,255,128, 64, 64,128,255,255,255,255,128, 64, 64,128,255,255); |
jah128 | 4:c2e933d53bea | 506 | if(animation_state == 6) _set_leds(255,220, 92, 32, 32, 92,220,255,255,220, 92, 32, 32, 92,220,255); |
jah128 | 4:c2e933d53bea | 507 | if(animation_state == 8) _set_leds(255,192, 64, 16, 16, 64,192,255,255,192, 64, 16, 16, 64,192,255); |
jah128 | 4:c2e933d53bea | 508 | if(animation_state == 10) _set_leds(255,160, 32, 8, 8, 32,160,255,255,160, 32, 8, 8, 32,160,255); |
jah128 | 4:c2e933d53bea | 509 | if(animation_state == 12) _set_leds(255,128, 16, 0, 0, 16,128,255,255,128, 16, 0, 0, 16,128,255); |
jah128 | 4:c2e933d53bea | 510 | if(animation_state == 13) _set_leds(255, 64, 4, 0, 0, 4, 64,255,255, 64, 4, 0, 0, 4, 64,255); |
jah128 | 4:c2e933d53bea | 511 | if(animation_state == 14) _set_leds(255, 0, 0, 0, 0, 0, 0,255,255, 0, 0, 0, 0, 0, 0,255); |
jah128 | 4:c2e933d53bea | 512 | animation_state ++; |
jah128 | 4:c2e933d53bea | 513 | if(animation_state == 16)animation_state = 0; |
jah128 | 4:c2e933d53bea | 514 | break; |
jah128 | 4:c2e933d53bea | 515 | case 11: |
jah128 | 4:c2e933d53bea | 516 | // Reverse orange chase |
jah128 | 4:c2e933d53bea | 517 | if(animation_state == 0) _set_leds( 64, 0, 0, 0, 0, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 64); |
jah128 | 4:c2e933d53bea | 518 | if(animation_state == 1) _set_leds(128, 64, 0, 0, 0, 0, 64,128,128, 64, 0, 0, 0, 0, 64,128); |
jah128 | 4:c2e933d53bea | 519 | if(animation_state == 2) _set_leds(255,128, 64, 0, 0, 64,128,255,255,128, 64, 0, 0, 64,128,255); |
jah128 | 4:c2e933d53bea | 520 | if(animation_state == 3) _set_leds(255,255,128, 64, 64,128,255,255,255,255,128, 64, 64,128,255,255); |
jah128 | 4:c2e933d53bea | 521 | if(animation_state == 4) _set_leds(128,255,255,128,128,255,255,128,128,255,255,128,128,255,255,128); |
jah128 | 4:c2e933d53bea | 522 | if(animation_state == 5) _set_leds( 64,128,255,255,255,255,128, 64, 64,128,255,255,255,255,128, 64); |
jah128 | 4:c2e933d53bea | 523 | if(animation_state == 6) _set_leds( 32, 92,220,255,255,220, 92, 32, 32, 92,220,255,255,220, 92, 32); |
jah128 | 4:c2e933d53bea | 524 | if(animation_state == 8) _set_leds( 16, 64,192,255,255,192, 64, 16, 16, 64,192,255,255,192, 64, 16); |
jah128 | 4:c2e933d53bea | 525 | if(animation_state == 10) _set_leds( 8, 32,160,255,255,160, 32, 8, 8, 32,160,255,255,160, 32, 8); |
jah128 | 4:c2e933d53bea | 526 | if(animation_state == 12) _set_leds( 0, 16,128,255,255,128, 16, 0, 0, 16,128,255,255,128, 16, 0); |
jah128 | 4:c2e933d53bea | 527 | if(animation_state == 13) _set_leds( 0, 4, 64,255,255, 64, 4, 0, 0, 4, 64,255,255, 64, 4, 0); |
jah128 | 4:c2e933d53bea | 528 | if(animation_state == 14) _set_leds( 0, 0, 0,255,255, 0, 0, 0, 0, 0, 0,255,255, 0, 0, 0); |
jah128 | 4:c2e933d53bea | 529 | animation_state ++; |
jah128 | 4:c2e933d53bea | 530 | if(animation_state == 16)animation_state = 0; |
jah128 | 4:c2e933d53bea | 531 | break; |
jah128 | 5:6da8daaeb9f7 | 532 | case 12: |
jah128 | 5:6da8daaeb9f7 | 533 | // Alternate red:green |
jah128 | 5:6da8daaeb9f7 | 534 | if(animation_state == 0) _set_leds( 64, 0, 64, 0, 64, 0, 64, 0, 0, 64, 0, 64, 0, 64, 0, 64); |
jah128 | 5:6da8daaeb9f7 | 535 | if(animation_state == 1) _set_leds(128, 0,128, 0,128, 0,128, 0, 0,128, 0,128, 0,128, 0,128); |
jah128 | 5:6da8daaeb9f7 | 536 | if(animation_state == 2) _set_leds(255, 0,255, 0,255, 0,255, 0, 0,255, 0,255, 0,255, 0,255); |
jah128 | 5:6da8daaeb9f7 | 537 | if(animation_state == 6) _set_leds(128, 0,128, 0,128, 0,128, 0, 0,128, 0,128, 0,128, 0,128); |
jah128 | 5:6da8daaeb9f7 | 538 | if(animation_state == 7) _set_leds( 64, 0, 64, 0, 64, 0, 64, 0, 0, 64, 0, 64, 0, 64, 0, 64); |
jah128 | 5:6da8daaeb9f7 | 539 | if(animation_state == 8) _set_leds( 0, 64, 0, 64, 0, 64, 0, 64, 64, 0, 64, 0, 64, 0, 64, 0); |
jah128 | 5:6da8daaeb9f7 | 540 | if(animation_state == 9) _set_leds( 0,128, 0,128, 0,128, 0,128,128, 0,128, 0,128, 0,128, 0); |
jah128 | 5:6da8daaeb9f7 | 541 | if(animation_state == 10) _set_leds( 0,255, 0,255, 0,255, 0,255,255, 0,255, 0,255, 0,255, 0); |
jah128 | 5:6da8daaeb9f7 | 542 | if(animation_state == 14) _set_leds( 0,128, 0,128, 0,128, 0,128,128, 0,128, 0,128, 0,128, 0); |
jah128 | 5:6da8daaeb9f7 | 543 | if(animation_state == 15) _set_leds( 0, 64, 0, 64, 0, 64, 0, 64, 64, 0, 64, 0, 64, 0, 64, 0); |
jah128 | 5:6da8daaeb9f7 | 544 | animation_state ++; |
jah128 | 5:6da8daaeb9f7 | 545 | if(animation_state == 16)animation_state = 0; |
jah128 | 5:6da8daaeb9f7 | 546 | break; |
jah128 | 0:8a2dd255c508 | 547 | } |
jah128 | 4:c2e933d53bea | 548 | } |