LED sequences for bot
Dependencies: mbed C12832_lcd LCD_fonts NeoStrip
Revision 0:56f7b47bf357, committed 2021-05-20
- Comitter:
- slackerjacker
- Date:
- Thu May 20 11:04:22 2021 +0000
- Commit message:
- LED for bot
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832_lcd.lib Thu May 20 11:04:22 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/dreschpe/code/C12832_lcd/#8f86576007d6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCD_fonts.lib Thu May 20 11:04:22 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/dreschpe/code/LCD_fonts/#d0b7d7bf1f56
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NeoStrip.lib Thu May 20 11:04:22 2021 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/aswild/code/NeoStrip/#f531a2be180d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gt.h Thu May 20 11:04:22 2021 +0000 @@ -0,0 +1,14 @@ +/**** gt.h ****/ + +const int gt_img[] = { + 0x122446, 0xffff00, 0xffff00, 0xffff00, 0xffff00, 0x122446, 0x122446, 0x122446, + 0xffff00, 0xffff00, 0x122446, 0x122446, 0x122446, 0x122446, 0x122446, 0x122446, + 0xffff00, 0x122446, 0x122446, 0x122446, 0x122446, 0x122446, 0x122446, 0x122446, + 0xffff00, 0x122446, 0x122446, 0xffff00, 0xffff00, 0xffff00, 0xffff00, 0xffff00, + 0xffff00, 0xffff00, 0x122446, 0x122446, 0xffff00, 0x122446, 0xffff00, 0x122446, + 0x122446, 0xffff00, 0xffff00, 0xffff00, 0xffff00, 0x122446, 0xffff00, 0x122446, + 0x122446, 0x122446, 0x122446, 0x122446, 0x122446, 0x122446, 0xffff00, 0x122446, + 0x122446, 0x122446, 0x122446, 0x122446, 0x122446, 0x122446, 0xffff00, 0x122446}; + +const int test_img[] = { + 0x122446, 0xffff00, 0xffff00, 0xffff00, 0xffff00, 0x122446, 0x122446, 0x122446}; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu May 20 11:04:22 2021 +0000 @@ -0,0 +1,388 @@ +#include "mbed.h" +#include "NeoStrip.h" +#include "gt.h" +#include "C12832_lcd.h" +#include "Arial_9.h" +#include "Small_7.h" + + +#define N 17 //number of leds +#define PATTERNS 3 + +Serial pc(USBTX, USBRX); +NeoStrip strip(p25, N); // DIN PIN with number of LEDs +NeoStrip led1(p25, 0); + +//////////////////////////////////// +//////note colours value below////// +//////////////////////////////////// + +float bright = 0.20; // 20% is plenty for indoor use +int red = 0xFF0000; +int orange = 0xFF8000; +int yellow = 0xFFFF00; +int green = 0x00FF44; +int blue = 0x00BFFF; +int indigo = 0x0F0082; +int violet = 0x8000B4; +int white = 0xFFFFFF; +int i = 0; +int z = 0xFFFFFF; +int hueToRGB(float h); + +int array[]={0xFF0000,0xFF8000,0xFFFF00,0x00FF44,0x00BFFF,0x0F0082,0x8000B4}; + +C12832_LCD LCD("LCD"); +//C12832_LCD lcd(p5, p7, p6, p8, p11); //jtb + +//variable that hold 1ms timer count, this can used in main to time stuff +int play_led_1ms_timer = 0; + +//set up a ticker funtion +////////////////////////////////////////////////////////////////////////// + +Ticker play_led_1ms_ticker; + +//this funtion runs every ms and increments lay_led_1ms_timer by 1 +void play_led_1ms(void) +{ +play_led_1ms_timer = play_led_1ms_timer+1; + +//stop overflow +if(play_led_1ms_timer> 1000000) + { + play_led_1ms_timer = 0; + } +} + +int main() +{ + // set up a function to play every 1.5 sec + play_led_1ms_ticker.attach(&play_led_1ms, 0.001); + +///////////////////////////////////////////////////////////////////////////// + + strip.setBrightness(bright); // set default brightness + strip.clear(); + strip.write(); + + pc.printf("1 - Bootup\n\r"); + pc.printf("2 - Bootdown\n\r"); + pc.printf("3 - Clear\n\r"); + pc.printf("4 - Happy\n\r"); + pc.printf("5 - Sad\n\r"); + pc.printf("6 - Idle\n\r"); + pc.printf("7 - Understood\n\r"); + while(true) + { + if (pc.readable()) + { + switch(pc.getc()) + { + case '1'://bootup sequence + + play_led_1ms_timer= 0; + do + { + LCD.cls(); + LCD.claim(stdout); + LCD.locate(10,0); + LCD.set_font((unsigned char*) Arial_9); + printf("Bot bootup"); + LCD.copy_to_lcd(); + LCD.set_font((unsigned char*) Small_7); + strip.clear(); + strip.write(); + wait_ms(1); + + strip.setPixel(0,red); + strip.write(); + wait_ms(100); + + strip.setPixel(1,orange); + strip.write(); + wait_ms(100); + + strip.setPixel(2,yellow); + strip.write(); + wait_ms(100); + + strip.setPixel(3,green); + strip.write(); + wait_ms(100); + + strip.setPixel(4,blue); + strip.write(); + wait_ms(100); + + strip.setPixel(5,indigo); + strip.write(); + wait_ms(100); + + strip.setPixel(6,violet); + strip.write(); + wait_ms(100); + + strip.setPixel(7,indigo); + strip.write(); + wait_ms(100); + + strip.setPixel(8,blue); + strip.write(); + wait_ms(100); + + strip.setPixel(9,green); + strip.write(); + wait_ms(100); + + strip.setPixel(10,yellow); + strip.write(); + wait_ms(100); + + strip.setPixel(11,orange); + strip.write(); + wait_ms(100); + + } + + while(play_led_1ms_timer < 1900); + + + + break; + + case '2'://bootdown sequence + + play_led_1ms_timer= 0; + + do + { + LCD.cls(); + LCD.claim(stdout); + LCD.locate(10,0); + LCD.set_font((unsigned char*) Arial_9); + printf("Shutting down"); + LCD.copy_to_lcd(); + LCD.set_font((unsigned char*) Small_7); + + + strip.setPixel(11,orange); + strip.write(); + wait_ms(1); + + strip.setPixel(10,yellow); + strip.write(); + wait_ms(1); + + strip.setPixel(9,green); + strip.write(); + wait_ms(1); + + strip.setPixel(8,blue); + strip.write(); + wait_ms(1); + + strip.setPixel(7,indigo); + strip.write(); + wait_ms(1); + + strip.setPixel(6,violet); + strip.write(); + wait_ms(1); + + strip.setPixel(5,indigo); + strip.write(); + wait_ms(1); + + strip.setPixel(4,blue); + strip.write(); + wait_ms(1); + + strip.setPixel(3,green); + strip.write(); + wait_ms(1); + + strip.setPixel(2,yellow); + strip.write(); + wait_ms(1); + + strip.setPixel(1,orange); + strip.write(); + wait_ms(1); + + strip.setPixel(0,red); + strip.write(); + wait_ms(1); + + + for (int i = 11; i >= 0; i--) + { + strip.setPixel(i,0,0,0); + strip.write(); + wait_ms(200); + } + } + + while(play_led_1ms_timer < 3000); + + break; + + case '3'://clear + LCD.cls(); + strip.clear(); + strip.write(); + + break; + + case '4': //happy + + + + //reset timer value to 0 + ////////////////////////////////////// + play_led_1ms_timer= 0; + + //repeat do while for 2000 ms see line 247 for while part + // this code will repeat untill play_led_1ms_timer > 2000 + do + { + LCD.cls(); + LCD.claim(stdout); + LCD.locate(10,0); + LCD.set_font((unsigned char*) Arial_9); + printf("Happy Bot"); + LCD.copy_to_lcd(); + LCD.set_font((unsigned char*) Small_7); + + + for (int i = 0; i < N; i++) + { + strip.setPixel(i,white); + strip.write(); + wait_ms(30); + } + + for (int i = 0; i < N; i++) + { + strip.setPixel(i,yellow); + strip.write(); + wait_ms(30); + } + + for (int i =0; i < N; i++) + { + strip.setPixel(i,orange); + strip.write(); + wait_ms(30); + } + } + while(play_led_1ms_timer < 2000); //timer value you want here i.e 2000 2s, 3500 3.5s etc + + strip.clear(); + strip.write(); + + break; + + case '5': + play_led_1ms_timer= 0; + do + { + LCD.cls(); + LCD.claim(stdout); + LCD.locate(10,0); + LCD.set_font((unsigned char*) Arial_9); + printf("Sad Bot"); + LCD.copy_to_lcd(); + LCD.set_font((unsigned char*) Small_7); + + for (float j = 0; j < 0.25; j=j+0.01) //float jack float i :-) , i = i+0.01 + { + //pc.printf("%f ",j); debug + strip.setBrightness(j); + + //need to write to pixcel to change brightness + for (int i = 0; i < 12; i++) + { + strip.setPixel(i,blue); + strip.write(); + wait_ms(3); + } + } + } + + while(play_led_1ms_timer < 2000); + + + + break; + + case '6': + play_led_1ms_timer= 0; + do + { + LCD.cls(); + LCD.claim(stdout); + LCD.locate(10,0); + LCD.set_font((unsigned char*) Arial_9); + printf("Idle bot"); + LCD.copy_to_lcd(); + LCD.set_font((unsigned char*) Small_7); + + for (int i=0;i<7;i++) + { + wait_ms(250); + for (int Q = 0; Q<12; Q++) + { + strip.setPixel(Q,array[i]); + strip.write(); + wait_ms(1); + } + } + } + while(play_led_1ms_timer < 3000); + + + + + + break; + + case '7': + play_led_1ms_timer= 0; + do + { + LCD.cls(); + LCD.claim(stdout); + LCD.locate(10,0); + LCD.set_font((unsigned char*) Arial_9); + printf("Affirmative"); + LCD.copy_to_lcd(); + LCD.set_font((unsigned char*) Small_7); + + for (float j = 0; j < 0.25; j=j+0.01) //float jack float i :-) , i = i+0.01 + { + //pc.printf("%f ",j); debug + strip.setBrightness(j); + + //need to write to pixel to change brightness + for (int i = 17; i > 0; i--) + { + strip.setPixel(i,green); + strip.write(); + wait_ms(3); + } + } + } + + while(play_led_1ms_timer < 2000); + + + + break; + }//End of switch + + }//end of if readable + + }//end of while(1) + +}//end of main() \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu May 20 11:04:22 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file