cleaned up verison

Dependencies:   mbed C12832_lcd LCD_fonts NeoStrip

Committer:
jasonberry
Date:
Tue Apr 20 13:11:03 2021 +0000
Revision:
3:d8620e883b77
Parent:
2:a04589b1a088
cleaned up j

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aswild 0:f38492690f0e 1 /*
jasonberry 1:a9f32c0c835d 2 * Adafruit NeoPixel example
aswild 0:f38492690f0e 3 *
aswild 0:f38492690f0e 4 * This program displays a couple simple patterns on an 8x8 NeoPixel matrix.
aswild 0:f38492690f0e 5 *
aswild 0:f38492690f0e 6 */
aswild 0:f38492690f0e 7
aswild 0:f38492690f0e 8 #include "mbed.h"
aswild 0:f38492690f0e 9 #include "NeoStrip.h"
aswild 0:f38492690f0e 10 #include "gt.h"
slackerjacker 2:a04589b1a088 11 #include "C12832_lcd.h"
slackerjacker 2:a04589b1a088 12 #include "Arial_9.h"
slackerjacker 2:a04589b1a088 13 #include "Small_7.h"
aswild 0:f38492690f0e 14
slackerjacker 2:a04589b1a088 15
slackerjacker 2:a04589b1a088 16 #define N 12 //number of leds
aswild 0:f38492690f0e 17 #define PATTERNS 3
aswild 0:f38492690f0e 18
jasonberry 3:d8620e883b77 19 Serial pc(USBTX, USBRX);
slackerjacker 2:a04589b1a088 20 NeoStrip strip(p25, N); // DIN PIN with number of LEDs
slackerjacker 2:a04589b1a088 21 NeoStrip led1(p25, 0);
jasonberry 3:d8620e883b77 22
jasonberry 3:d8620e883b77 23 ////////////////////////////////////
jasonberry 3:d8620e883b77 24 //////note colours value below//////
jasonberry 3:d8620e883b77 25 ////////////////////////////////////
jasonberry 3:d8620e883b77 26
jasonberry 3:d8620e883b77 27 float bright = 0.20; // 20% is plenty for indoor use
jasonberry 3:d8620e883b77 28 int red = 0xFF0000;
jasonberry 3:d8620e883b77 29 int orange = 0xFF8000;
jasonberry 3:d8620e883b77 30 int yellow = 0xFFFF00;
jasonberry 3:d8620e883b77 31 int green = 0x00FF44;
jasonberry 3:d8620e883b77 32 int blue = 0x00BFFF;
jasonberry 3:d8620e883b77 33 int indigo = 0x0F0082;
jasonberry 3:d8620e883b77 34 int violet = 0x8000B4;
jasonberry 3:d8620e883b77 35 int white = 0xFFFFFF;
jasonberry 3:d8620e883b77 36 int i = 0;
jasonberry 3:d8620e883b77 37 int hueToRGB(float h);
slackerjacker 2:a04589b1a088 38
jasonberry 3:d8620e883b77 39
jasonberry 3:d8620e883b77 40 //C12832_LCD LCD("LCD");
jasonberry 3:d8620e883b77 41 //C12832_LCD lcd(p5, p7, p6, p8, p11); //jtb
jasonberry 3:d8620e883b77 42
jasonberry 3:d8620e883b77 43 //variable that hold 1ms timer count, this can used in main to time stuff
jasonberry 3:d8620e883b77 44 int play_led_1ms_timer = 0;
jasonberry 3:d8620e883b77 45
jasonberry 3:d8620e883b77 46 //set up a ticker funtion
jasonberry 3:d8620e883b77 47 //////////////////////////////////////////////////////////////////////////
jasonberry 3:d8620e883b77 48
jasonberry 3:d8620e883b77 49 Ticker play_led_1ms_ticker;
aswild 0:f38492690f0e 50
jasonberry 3:d8620e883b77 51 //this funtion runs every ms and increments lay_led_1ms_timer by 1
jasonberry 3:d8620e883b77 52 void play_led_1ms(void)
jasonberry 3:d8620e883b77 53 {
jasonberry 3:d8620e883b77 54 play_led_1ms_timer = play_led_1ms_timer+1;
jasonberry 3:d8620e883b77 55
jasonberry 3:d8620e883b77 56 //stop overflow
jasonberry 3:d8620e883b77 57 if(play_led_1ms_timer> 1000000)
jasonberry 3:d8620e883b77 58 {
jasonberry 3:d8620e883b77 59 play_led_1ms_timer = 0;
jasonberry 3:d8620e883b77 60 }
jasonberry 3:d8620e883b77 61 }
aswild 0:f38492690f0e 62
aswild 0:f38492690f0e 63 int main()
aswild 0:f38492690f0e 64 {
jasonberry 3:d8620e883b77 65 // set up a function to play every 1.5 sec
jasonberry 3:d8620e883b77 66 play_led_1ms_ticker.attach(&play_led_1ms, 0.001);
jasonberry 3:d8620e883b77 67
jasonberry 3:d8620e883b77 68 /////////////////////////////////////////////////////////////////////////////
slackerjacker 2:a04589b1a088 69
jasonberry 3:d8620e883b77 70 strip.setBrightness(bright); // set default brightness
jasonberry 3:d8620e883b77 71 strip.clear();
jasonberry 3:d8620e883b77 72 strip.write();
slackerjacker 2:a04589b1a088 73
slackerjacker 2:a04589b1a088 74 pc.printf("1 - Bootup\n\r");
slackerjacker 2:a04589b1a088 75 pc.printf("2 - Bootdown\n\r");
slackerjacker 2:a04589b1a088 76 pc.printf("3 - Clear\n\r");
slackerjacker 2:a04589b1a088 77 pc.printf("4 - Happy\n\r");
slackerjacker 2:a04589b1a088 78 pc.printf("5 - Sad\n\r");
slackerjacker 2:a04589b1a088 79
jasonberry 1:a9f32c0c835d 80 while(true)
jasonberry 3:d8620e883b77 81 {
jasonberry 3:d8620e883b77 82 if (pc.readable())
jasonberry 3:d8620e883b77 83 {
jasonberry 3:d8620e883b77 84 switch(pc.getc())
jasonberry 3:d8620e883b77 85 {
jasonberry 3:d8620e883b77 86 case '1'://bootup sequence
jasonberry 3:d8620e883b77 87
jasonberry 3:d8620e883b77 88 //LCD.cls();
jasonberry 3:d8620e883b77 89 strip.clear();
jasonberry 3:d8620e883b77 90 strip.write();
jasonberry 3:d8620e883b77 91 wait_ms(200);
slackerjacker 2:a04589b1a088 92
jasonberry 3:d8620e883b77 93 strip.setPixel(0,red);
jasonberry 3:d8620e883b77 94 strip.write();
jasonberry 3:d8620e883b77 95 wait_ms(200);
jasonberry 3:d8620e883b77 96
jasonberry 3:d8620e883b77 97 strip.setPixel(1,orange);
jasonberry 3:d8620e883b77 98 strip.write();
jasonberry 3:d8620e883b77 99 wait_ms(200);
jasonberry 3:d8620e883b77 100
jasonberry 3:d8620e883b77 101 strip.setPixel(2,yellow);
jasonberry 3:d8620e883b77 102 strip.write();
jasonberry 3:d8620e883b77 103 wait_ms(200);
jasonberry 3:d8620e883b77 104
jasonberry 3:d8620e883b77 105 strip.setPixel(3,green);
jasonberry 3:d8620e883b77 106 strip.write();
jasonberry 3:d8620e883b77 107 wait_ms(200);
jasonberry 3:d8620e883b77 108
jasonberry 3:d8620e883b77 109 strip.setPixel(4,blue);
jasonberry 3:d8620e883b77 110 strip.write();
jasonberry 3:d8620e883b77 111 wait_ms(200);
jasonberry 3:d8620e883b77 112
jasonberry 3:d8620e883b77 113 strip.setPixel(5,indigo);
jasonberry 3:d8620e883b77 114 strip.write();
jasonberry 3:d8620e883b77 115 wait_ms(200);
jasonberry 3:d8620e883b77 116
jasonberry 3:d8620e883b77 117 strip.setPixel(6,violet);
jasonberry 3:d8620e883b77 118 strip.write();
jasonberry 3:d8620e883b77 119 wait_ms(200);
jasonberry 3:d8620e883b77 120
jasonberry 3:d8620e883b77 121 strip.setPixel(7,indigo);
jasonberry 3:d8620e883b77 122 strip.write();
jasonberry 3:d8620e883b77 123 wait_ms(200);
jasonberry 3:d8620e883b77 124
jasonberry 3:d8620e883b77 125 strip.setPixel(8,blue);
jasonberry 3:d8620e883b77 126 strip.write();
jasonberry 3:d8620e883b77 127 wait_ms(200);
slackerjacker 2:a04589b1a088 128
jasonberry 3:d8620e883b77 129 strip.setPixel(9,green);
jasonberry 3:d8620e883b77 130 strip.write();
jasonberry 3:d8620e883b77 131 wait_ms(200);
jasonberry 3:d8620e883b77 132
jasonberry 3:d8620e883b77 133 strip.setPixel(10,yellow);
jasonberry 3:d8620e883b77 134 strip.write();
jasonberry 3:d8620e883b77 135 wait_ms(200);
slackerjacker 2:a04589b1a088 136
jasonberry 3:d8620e883b77 137 strip.setPixel(11,orange);
jasonberry 3:d8620e883b77 138 strip.write();
jasonberry 3:d8620e883b77 139 wait_ms(200);
jasonberry 3:d8620e883b77 140
jasonberry 3:d8620e883b77 141 break;
jasonberry 3:d8620e883b77 142
jasonberry 3:d8620e883b77 143 case '2'://bootdown sequence
jasonberry 3:d8620e883b77 144
jasonberry 3:d8620e883b77 145 //LCD.cls();
slackerjacker 2:a04589b1a088 146
jasonberry 3:d8620e883b77 147 strip.setPixel(11,orange);
jasonberry 3:d8620e883b77 148 strip.write();
jasonberry 3:d8620e883b77 149 wait_ms(1);
slackerjacker 2:a04589b1a088 150
jasonberry 3:d8620e883b77 151 strip.setPixel(10,yellow);
jasonberry 3:d8620e883b77 152 strip.write();
jasonberry 3:d8620e883b77 153 wait_ms(1);
slackerjacker 2:a04589b1a088 154
jasonberry 3:d8620e883b77 155 strip.setPixel(9,green);
jasonberry 3:d8620e883b77 156 strip.write();
jasonberry 3:d8620e883b77 157 wait_ms(1);
slackerjacker 2:a04589b1a088 158
jasonberry 3:d8620e883b77 159 strip.setPixel(8,blue);
jasonberry 3:d8620e883b77 160 strip.write();
jasonberry 3:d8620e883b77 161 wait_ms(1);
slackerjacker 2:a04589b1a088 162
jasonberry 3:d8620e883b77 163 strip.setPixel(7,indigo);
jasonberry 3:d8620e883b77 164 strip.write();
jasonberry 3:d8620e883b77 165 wait_ms(1);
slackerjacker 2:a04589b1a088 166
jasonberry 3:d8620e883b77 167 strip.setPixel(6,violet);
jasonberry 3:d8620e883b77 168 strip.write();
jasonberry 3:d8620e883b77 169 wait_ms(1);
slackerjacker 2:a04589b1a088 170
jasonberry 3:d8620e883b77 171 strip.setPixel(5,indigo);
jasonberry 3:d8620e883b77 172 strip.write();
jasonberry 3:d8620e883b77 173 wait_ms(1);
slackerjacker 2:a04589b1a088 174
jasonberry 3:d8620e883b77 175 strip.setPixel(4,blue);
jasonberry 3:d8620e883b77 176 strip.write();
jasonberry 3:d8620e883b77 177 wait_ms(1);
slackerjacker 2:a04589b1a088 178
jasonberry 3:d8620e883b77 179 strip.setPixel(3,green);
jasonberry 3:d8620e883b77 180 strip.write();
jasonberry 3:d8620e883b77 181 wait_ms(1);
slackerjacker 2:a04589b1a088 182
jasonberry 3:d8620e883b77 183 strip.setPixel(2,yellow);
jasonberry 3:d8620e883b77 184 strip.write();
jasonberry 3:d8620e883b77 185 wait_ms(1);
slackerjacker 2:a04589b1a088 186
jasonberry 3:d8620e883b77 187 strip.setPixel(1,orange);
jasonberry 3:d8620e883b77 188 strip.write();
jasonberry 3:d8620e883b77 189 wait_ms(1);
slackerjacker 2:a04589b1a088 190
jasonberry 3:d8620e883b77 191 strip.setPixel(0,red);
jasonberry 3:d8620e883b77 192 strip.write();
jasonberry 3:d8620e883b77 193 wait_ms(1);
jasonberry 3:d8620e883b77 194
jasonberry 3:d8620e883b77 195 for (int i = 11; i >= 0; i--)
jasonberry 3:d8620e883b77 196 {
jasonberry 3:d8620e883b77 197 strip.setPixel(i,0,0,0);
jasonberry 3:d8620e883b77 198 strip.write();
jasonberry 3:d8620e883b77 199 wait_ms(500);
jasonberry 3:d8620e883b77 200 }
jasonberry 3:d8620e883b77 201
jasonberry 3:d8620e883b77 202 break;
jasonberry 3:d8620e883b77 203
jasonberry 3:d8620e883b77 204 case '3'://clear
jasonberry 3:d8620e883b77 205 //LCD.cls();
jasonberry 3:d8620e883b77 206 strip.clear();
jasonberry 3:d8620e883b77 207 strip.write();
jasonberry 3:d8620e883b77 208
jasonberry 3:d8620e883b77 209 break;
jasonberry 3:d8620e883b77 210
jasonberry 3:d8620e883b77 211 case '4':
slackerjacker 2:a04589b1a088 212
jasonberry 3:d8620e883b77 213 //LCD.claim(stdout);
jasonberry 3:d8620e883b77 214 //LCD.locate(10,0);
jasonberry 3:d8620e883b77 215 //LCD.set_font((unsigned char*) Arial_9);
jasonberry 3:d8620e883b77 216 //printf("Happy Bot");
jasonberry 3:d8620e883b77 217 //LCD.copy_to_lcd();
jasonberry 3:d8620e883b77 218 //LCD.set_font((unsigned char*) Small_7);
slackerjacker 2:a04589b1a088 219
jasonberry 3:d8620e883b77 220 //reset timer value to 0
jasonberry 3:d8620e883b77 221 //////////////////////////////////////
jasonberry 3:d8620e883b77 222 play_led_1ms_timer= 0;
jasonberry 3:d8620e883b77 223
jasonberry 3:d8620e883b77 224 //repeat do while for 2000 ms see line 247 for while part
jasonberry 3:d8620e883b77 225 // this code will repeat untill play_led_1ms_timer > 2000
jasonberry 3:d8620e883b77 226 do
jasonberry 3:d8620e883b77 227 {
jasonberry 3:d8620e883b77 228 for (int i = 0; i < N; i++)
jasonberry 3:d8620e883b77 229 {
jasonberry 3:d8620e883b77 230 strip.setPixel(i,white);
jasonberry 3:d8620e883b77 231 strip.write();
jasonberry 3:d8620e883b77 232 wait_ms(30);
jasonberry 3:d8620e883b77 233 }
slackerjacker 2:a04589b1a088 234
jasonberry 3:d8620e883b77 235 for (int i = 0; i < N; i++)
jasonberry 3:d8620e883b77 236 {
jasonberry 3:d8620e883b77 237 strip.setPixel(i,yellow);
jasonberry 3:d8620e883b77 238 strip.write();
jasonberry 3:d8620e883b77 239 wait_ms(30);
jasonberry 3:d8620e883b77 240 }
jasonberry 3:d8620e883b77 241
jasonberry 3:d8620e883b77 242 for (int i =0; i < N; i++)
jasonberry 3:d8620e883b77 243 {
jasonberry 3:d8620e883b77 244 strip.setPixel(i,orange);
jasonberry 3:d8620e883b77 245 strip.write();
jasonberry 3:d8620e883b77 246 wait_ms(30);
jasonberry 3:d8620e883b77 247 }
jasonberry 3:d8620e883b77 248 }
jasonberry 3:d8620e883b77 249 while(play_led_1ms_timer < 2000); //timer value you want here i.e 2000 2s, 3500 3.5s etc
jasonberry 3:d8620e883b77 250
jasonberry 3:d8620e883b77 251 strip.clear();
jasonberry 3:d8620e883b77 252 strip.write();
jasonberry 3:d8620e883b77 253
jasonberry 3:d8620e883b77 254 break;
slackerjacker 2:a04589b1a088 255
jasonberry 3:d8620e883b77 256 case '5':
jasonberry 1:a9f32c0c835d 257
jasonberry 3:d8620e883b77 258 for (float j = 0; j < 0.3; j=j+0.01) //float jack float i :-) , i = i+0.01
jasonberry 3:d8620e883b77 259 {
jasonberry 3:d8620e883b77 260 //pc.printf("%f ",j); debug
jasonberry 3:d8620e883b77 261 strip.setBrightness(j);
jasonberry 3:d8620e883b77 262
jasonberry 3:d8620e883b77 263 //need to write to pixcel to change brightness
jasonberry 3:d8620e883b77 264 for (int i = 0; i < 12; i++)
jasonberry 3:d8620e883b77 265 {
jasonberry 3:d8620e883b77 266 strip.setPixel(i,blue);
jasonberry 3:d8620e883b77 267 strip.write();
jasonberry 3:d8620e883b77 268 wait_ms(1);
jasonberry 3:d8620e883b77 269 }
jasonberry 3:d8620e883b77 270 wait_ms(200);
jasonberry 3:d8620e883b77 271 }
jasonberry 3:d8620e883b77 272
jasonberry 3:d8620e883b77 273 strip.clear();
jasonberry 3:d8620e883b77 274 strip.write();
jasonberry 3:d8620e883b77 275
jasonberry 3:d8620e883b77 276 break;
jasonberry 3:d8620e883b77 277 }//End of switch
jasonberry 3:d8620e883b77 278
jasonberry 3:d8620e883b77 279 }//end of if readable
jasonberry 3:d8620e883b77 280
jasonberry 3:d8620e883b77 281 }//end of while(1)
jasonberry 3:d8620e883b77 282
jasonberry 3:d8620e883b77 283 }//end of main()