Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed C12832_lcd LCD_fonts NeoStrip
main.cpp
00001 /* 00002 * Adafruit NeoPixel example 00003 * 00004 * This program displays a couple simple patterns on an 8x8 NeoPixel matrix. 00005 * 00006 */ 00007 00008 #include "mbed.h" 00009 #include "NeoStrip.h" 00010 #include "gt.h" 00011 #include "C12832_lcd.h" 00012 #include "Arial_9.h" 00013 #include "Small_7.h" 00014 00015 00016 #define N 12 //number of leds 00017 #define PATTERNS 3 00018 00019 Serial pc(USBTX, USBRX); 00020 NeoStrip strip(p25, N); // DIN PIN with number of LEDs 00021 NeoStrip led1(p25, 0); 00022 00023 //////////////////////////////////// 00024 //////note colours value below////// 00025 //////////////////////////////////// 00026 00027 float bright = 0.20; // 20% is plenty for indoor use 00028 int red = 0xFF0000; 00029 int orange = 0xFF8000; 00030 int yellow = 0xFFFF00; 00031 int green = 0x00FF44; 00032 int blue = 0x00BFFF; 00033 int indigo = 0x0F0082; 00034 int violet = 0x8000B4; 00035 int white = 0xFFFFFF; 00036 int i = 0; 00037 int hueToRGB(float h); 00038 00039 00040 //C12832_LCD LCD("LCD"); 00041 //C12832_LCD lcd(p5, p7, p6, p8, p11); //jtb 00042 00043 //variable that hold 1ms timer count, this can used in main to time stuff 00044 int play_led_1ms_timer = 0; 00045 00046 //set up a ticker funtion 00047 ////////////////////////////////////////////////////////////////////////// 00048 00049 Ticker play_led_1ms_ticker; 00050 00051 //this funtion runs every ms and increments lay_led_1ms_timer by 1 00052 void play_led_1ms(void) 00053 { 00054 play_led_1ms_timer = play_led_1ms_timer+1; 00055 00056 //stop overflow 00057 if(play_led_1ms_timer> 1000000) 00058 { 00059 play_led_1ms_timer = 0; 00060 } 00061 } 00062 00063 int main() 00064 { 00065 // set up a function to play every 1.5 sec 00066 play_led_1ms_ticker.attach(&play_led_1ms, 0.001); 00067 00068 ///////////////////////////////////////////////////////////////////////////// 00069 00070 strip.setBrightness(bright); // set default brightness 00071 strip.clear(); 00072 strip.write(); 00073 00074 pc.printf("1 - Bootup\n\r"); 00075 pc.printf("2 - Bootdown\n\r"); 00076 pc.printf("3 - Clear\n\r"); 00077 pc.printf("4 - Happy\n\r"); 00078 pc.printf("5 - Sad\n\r"); 00079 00080 while(true) 00081 { 00082 if (pc.readable()) 00083 { 00084 switch(pc.getc()) 00085 { 00086 case '1'://bootup sequence 00087 00088 //LCD.cls(); 00089 strip.clear(); 00090 strip.write(); 00091 wait_ms(200); 00092 00093 strip.setPixel(0,red); 00094 strip.write(); 00095 wait_ms(200); 00096 00097 strip.setPixel(1,orange); 00098 strip.write(); 00099 wait_ms(200); 00100 00101 strip.setPixel(2,yellow); 00102 strip.write(); 00103 wait_ms(200); 00104 00105 strip.setPixel(3,green); 00106 strip.write(); 00107 wait_ms(200); 00108 00109 strip.setPixel(4,blue); 00110 strip.write(); 00111 wait_ms(200); 00112 00113 strip.setPixel(5,indigo); 00114 strip.write(); 00115 wait_ms(200); 00116 00117 strip.setPixel(6,violet); 00118 strip.write(); 00119 wait_ms(200); 00120 00121 strip.setPixel(7,indigo); 00122 strip.write(); 00123 wait_ms(200); 00124 00125 strip.setPixel(8,blue); 00126 strip.write(); 00127 wait_ms(200); 00128 00129 strip.setPixel(9,green); 00130 strip.write(); 00131 wait_ms(200); 00132 00133 strip.setPixel(10,yellow); 00134 strip.write(); 00135 wait_ms(200); 00136 00137 strip.setPixel(11,orange); 00138 strip.write(); 00139 wait_ms(200); 00140 00141 break; 00142 00143 case '2'://bootdown sequence 00144 00145 //LCD.cls(); 00146 00147 strip.setPixel(11,orange); 00148 strip.write(); 00149 wait_ms(1); 00150 00151 strip.setPixel(10,yellow); 00152 strip.write(); 00153 wait_ms(1); 00154 00155 strip.setPixel(9,green); 00156 strip.write(); 00157 wait_ms(1); 00158 00159 strip.setPixel(8,blue); 00160 strip.write(); 00161 wait_ms(1); 00162 00163 strip.setPixel(7,indigo); 00164 strip.write(); 00165 wait_ms(1); 00166 00167 strip.setPixel(6,violet); 00168 strip.write(); 00169 wait_ms(1); 00170 00171 strip.setPixel(5,indigo); 00172 strip.write(); 00173 wait_ms(1); 00174 00175 strip.setPixel(4,blue); 00176 strip.write(); 00177 wait_ms(1); 00178 00179 strip.setPixel(3,green); 00180 strip.write(); 00181 wait_ms(1); 00182 00183 strip.setPixel(2,yellow); 00184 strip.write(); 00185 wait_ms(1); 00186 00187 strip.setPixel(1,orange); 00188 strip.write(); 00189 wait_ms(1); 00190 00191 strip.setPixel(0,red); 00192 strip.write(); 00193 wait_ms(1); 00194 00195 for (int i = 11; i >= 0; i--) 00196 { 00197 strip.setPixel(i,0,0,0); 00198 strip.write(); 00199 wait_ms(500); 00200 } 00201 00202 break; 00203 00204 case '3'://clear 00205 //LCD.cls(); 00206 strip.clear(); 00207 strip.write(); 00208 00209 break; 00210 00211 case '4': 00212 00213 //LCD.claim(stdout); 00214 //LCD.locate(10,0); 00215 //LCD.set_font((unsigned char*) Arial_9); 00216 //printf("Happy Bot"); 00217 //LCD.copy_to_lcd(); 00218 //LCD.set_font((unsigned char*) Small_7); 00219 00220 //reset timer value to 0 00221 ////////////////////////////////////// 00222 play_led_1ms_timer= 0; 00223 00224 //repeat do while for 2000 ms see line 247 for while part 00225 // this code will repeat untill play_led_1ms_timer > 2000 00226 do 00227 { 00228 for (int i = 0; i < N; i++) 00229 { 00230 strip.setPixel(i,white); 00231 strip.write(); 00232 wait_ms(30); 00233 } 00234 00235 for (int i = 0; i < N; i++) 00236 { 00237 strip.setPixel(i,yellow); 00238 strip.write(); 00239 wait_ms(30); 00240 } 00241 00242 for (int i =0; i < N; i++) 00243 { 00244 strip.setPixel(i,orange); 00245 strip.write(); 00246 wait_ms(30); 00247 } 00248 } 00249 while(play_led_1ms_timer < 2000); //timer value you want here i.e 2000 2s, 3500 3.5s etc 00250 00251 strip.clear(); 00252 strip.write(); 00253 00254 break; 00255 00256 case '5': 00257 00258 for (float j = 0; j < 0.3; j=j+0.01) //float jack float i :-) , i = i+0.01 00259 { 00260 //pc.printf("%f ",j); debug 00261 strip.setBrightness(j); 00262 00263 //need to write to pixcel to change brightness 00264 for (int i = 0; i < 12; i++) 00265 { 00266 strip.setPixel(i,blue); 00267 strip.write(); 00268 wait_ms(1); 00269 } 00270 wait_ms(200); 00271 } 00272 00273 strip.clear(); 00274 strip.write(); 00275 00276 break; 00277 }//End of switch 00278 00279 }//end of if readable 00280 00281 }//end of while(1) 00282 00283 }//end of main()
Generated on Thu Aug 18 2022 19:04:34 by
1.7.2