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.
main.cpp
00001 #include "mbed.h" 00002 #include "WS2812.h" 00003 00004 const int size = 300; //number of LED´s 00005 int line = 25; //length of Flash 00006 DigitalOut myled(LED1); 00007 WS2812 strip (p5,size,6,17,9,14); //mbed 4088: 10,24,20,22 see https://developer.mbed.org/users/bridadan/code/WS2812/ 00008 00009 //Ticker speed; 00010 //Ticker baum; 00011 00012 00013 int Buffer[size + 70]; //a buffer is never to big 00014 int dir = 1; 00015 int spe = 5; 00016 int spe_2 = 70; 00017 int nd = 1; 00018 int run_i = 1; 00019 00020 // Short Light {Startposition,Direktion} Startposition must > 10 and < (size-10) 00021 int single[5][2]={{9,1},{140,1},{280,1},{120,-1},{260,-1}}; 00022 00023 00024 00025 00026 00027 int color_set(uint8_t rot,uint8_t gruen, uint8_t blau, uint8_t alpha) 00028 { 00029 return ((alpha<<24) + (rot<<16) + (gruen<<8) + blau); 00030 } 00031 00032 00033 //change speed 00034 void do_speed() 00035 { 00036 spe_2 = spe_2 + dir; 00037 if (spe_2 > 180) dir = -1; 00038 if (spe_2 < 60) dir = 1; 00039 spe = spe_2/20; 00040 } 00041 00042 00043 void do_single(int num,int c) 00044 { 00045 Buffer[single[num][0]] = color_set(((c&0x00FF0000)>>16)-nd%30, 00046 ((c&0x0000FF00)>>8)+nd%35,(c&0x000000FF)+nd%10,250); 00047 double ran = rand()%2; 00048 single[num][0] = single[num][0] + ((ran)* single[num][1]); 00049 if (single[num][0] > (size-13)) single[num][1]= -1; 00050 if (single[num][0] < 8 ) single[num][1] = 1; 00051 Buffer[single[num][0]-3] = color_set(0,0,0,0); 00052 Buffer[single[num][0]-4] = color_set(0,0,0,0); 00053 Buffer[single[num][0]+3] = color_set(0,0,0,0); 00054 Buffer[single[num][0]+4] = color_set(0,0,0,0); 00055 } 00056 00057 00058 void do_baum() 00059 { 00060 for (int i = size - line; i < size; i++) 00061 { 00062 Buffer[i] &= color_set(124+spe*12+nd%60,255-spe*27+nd%45,124-spe*13-nd%35,240-nd%200); 00063 nd+=12; 00064 } 00065 } 00066 00067 void do_run() 00068 { 00069 if (run_i < line) 00070 { 00071 for (int j = 0; j < spe; j++) Buffer[run_i+j] = color_set(spe*20-nd%15,253-spe*20,124-spe*13+nd%25,240); 00072 } 00073 else 00074 { 00075 for (int j = 0; j < spe; j++) Buffer[run_i+j] = color_set(spe*27-nd%25,253-spe*27,124-spe*13+nd%55,240); 00076 for (int j = 0; j < spe; j++) Buffer[run_i+j-line] = color_set(0,0,0,0); 00077 } 00078 00079 run_i+=spe; 00080 00081 if(run_i > size) run_i = 0; 00082 } 00083 00084 void show(bool i) 00085 { 00086 do_single(0,0x00ff0000); 00087 do_single(1,0x0006de08); 00088 do_single(2,0x000000df); 00089 do_single(3,0xdeadbeef); 00090 do_single(4,0x00442288); 00091 do_baum(); 00092 do_speed(); 00093 do_run(); 00094 if (i>0) for (int a=0; a<size;a++){ Buffer[a]^= 4294967295;}; 00095 strip.write(Buffer); 00096 } 00097 00098 int main() 00099 { 00100 while(1) 00101 { 00102 show(0); 00103 myled = !myled; 00104 } 00105 }
Generated on Wed Jul 13 2022 07:51:53 by
1.7.2