//simple mouse ws2812B rainbow //ws2812 #include #define LED_PIN PB8 #define BRIGHTNESS 255 #define LED_TYPE WS2812B #define COLOR_ORDER GRB #define screeny 15 CRGB leds[screeny]; CRGBPalette16 currentPalette; TBlendType currentBlending; #define UPDATES_PER_SECOND 5000 extern CRGBPalette16 myRedWhiteBluePalette; // clicker #define tmitte PA0 #define tlinks PA1 #define trechts PA2 void setup () { delay(500); pinMode(tmitte, INPUT); pinMode(tlinks, INPUT); pinMode(trechts, INPUT); FastLED.addLeds(leds, screeny).setCorrection( TypicalLEDStrip ); FastLED.setBrightness( BRIGHTNESS ); currentPalette = RainbowColors_p; currentBlending = BLEND; } int8_t zeit1; void loop () { istinput(); zeitreise(); machschon(); apply(); } int8_t onpress[17]; int8_t nenrand=0; boolean clicked=false; void istinput() { if (zeit1 >=1) { if (digitalRead(tmitte) == LOW && onpress[8] ==0) { onpress[8] =1; mitte();} if (onpress[8] == 1) { onpress[9]++; }//spiel(melodie2); if (onpress[9] >= 3) { onpress[9] =0; onpress[8]=0; } if (digitalRead(tlinks) == LOW && onpress[10] ==0) { onpress[10] =1; links();} if (onpress[10] == 1) { onpress[11]++;} if (onpress[11] >= 3) { onpress[11] =0; onpress[10]=0; } if (digitalRead(trechts) == LOW && onpress[12] ==0) { onpress[12] =1; rechts();} if (onpress[12] == 1) { onpress[13]++;} if (onpress[13] >= 3) { onpress[13] =0; onpress[12]=0; } zeit1=0;} if (digitalRead(trechts) == HIGH && digitalRead(tlinks) == HIGH && digitalRead(tmitte) == HIGH) {clicked=false; zufall(); nenrand=random(0,3);} // if (onpress[8] ==1 || onpress[10] ==1 || onpress[12] ==1) {clicked=true; } if (digitalRead(trechts) == LOW || digitalRead(tlinks) == LOW || digitalRead(tmitte) == LOW) {clicked=true; } } long zentelsec=millis(); long hundsec=millis(); long maintime =millis(); int32_t zufallc=0; int32_t slower,alles,allesbt,allespeed,allescc,allesb,allbrightup,zufall1,zufall2,zufall3; int16_t flashing=0; void zeitreise(void){ while ((millis()- maintime) >= 3) { zeit1++; slower++; allescc++; allesb++;maintime = millis();} while ((millis()- zentelsec) >= 100) { zufall1++,zufall2++; allesbt++;zufallc++; alles++; zentelsec = millis();} while ((millis()- hundsec) >= 10) { flashing++; hundsec = millis();} } int32_t leddata[screeny][10]; //0 bright,1 brightsol,2 brightspeed,3 time, 4 color,5 colorsol,6 colorspeed,7 stepptz int8_t tudas[10]={0,0,1,0,1,1}; int16_t allbright,allspeedb,allcolor,allspeedc,allbmax,allbmin; int16_t colorpos,color; void machschon() { //0 wuselzu helligkeit,1 wuselzu farbe, 2 laufrainbow if (slower >1) { if (tudas[0] ==0 || clicked== true) { //zuhelligkeit for( int bb = 0; bb < screeny; bb++) { if (leddata[bb][0] >= leddata[bb][1] ) { leddata[bb][0]-=leddata[bb][2];} if (leddata[bb][0] < leddata[bb][1] ) {leddata[bb][0] +=leddata[bb][2];} }} if (tudas[1] ==0 || clicked== true) { //zufabe for( int b = 0; b < screeny; b++) { if (leddata[b][4] >= leddata[b][5] && leddata[b][4] >leddata[b][6]) {leddata[b][4]-=leddata[b][6];} if (leddata[b][4] < leddata[b][5]) {leddata[b][4]+=leddata[b][6];} }} slower=0; } if (tudas[2] ==0 && clicked==false) { //lauf regenbogen colorpos+=1+(allspeedc/2); if (colorpos >255) {colorpos=0;} color=colorpos; for( int16_t b2 = 0; b2 < screeny; b2++) {color+=1+(allcolor/6); leddata[b2][4]=color; leddata[b2][0]=allbright;} } if (tudas[2] ==1 && clicked==false) { //lauf regenbogen vorne hinten colorpos-=1+(allspeedc/6); if (colorpos <1) {colorpos=255;} color=colorpos; for( int16_t b22 = 0; b22 < 4; b22++) { color+=1+(allcolor/4); leddata[b22][4]=color; leddata[b22][0]=allbright; leddata[screeny-(b22+8)][4]=color; leddata[screeny-(b22+8)][0]=allbright; if (b22 >=2) { leddata[b22+6][4]=color; leddata[(b22+6)][0]=allbright;} if (b22 >=2) { leddata[screeny-(b22+2)][4]=color; leddata[screeny-(b22+2)][0]=allbright;} if (b22 ==1) { leddata[12][4]=color; leddata[12][0]=allbright;} } } if (tudas[2] ==2 && clicked==false) { if (zufallc >20) { for( int16_t b3 = 0; b3 < screeny; b3++) { if ( leddata[b3][7]==0) {leddata[b3][1]=255; leddata[b3][2]=random(1,6); leddata[b3][7]=1; } if (leddata[b3][0] >= leddata[b3][1]&& leddata[b3][7]==1) {leddata[b3][5]=random(0,254); leddata[b3][7]=2; leddata[b3][6]=random(1,3); } if (leddata[b3][4] >= leddata[b3][5]&& leddata[b3][7]==2) {leddata[b3][1]=0; leddata[b3][7]=3; leddata[b3][3]=random(1,5); } if (leddata[b3][1] >= leddata[b3][0]&& leddata[b3][7]==3) {leddata[b3][5]=random(0,254); leddata[b3][7]=0; leddata[b3][6]=random(1,5); } } zufallc=random(5,15);} } if (tudas[5] ==3 && clicked==false) { //lauf regenbogen for( int16_t b4 = 0; b4 < screeny; b4++) { leddata[b4][0]=allbright; leddata[b4][4]=allcolor; } } toogle(); } void toogle(){ if (flashing >128) {flashing=0;} if (alles > 40) {alles=random(0,25); allspeedc=random(1,10); allspeedb=random(1,8);} if (allesbt > 40) {allesbt=random(0,30); allbmax=random(180,255); allbmin=random(1,90);} if (allesb >allspeedb && allbrightup==0) {allesb=0;allbright++; } if (allesb >allspeedb && allbrightup==1) {allesb=0;allbright--; } if (allbright >=allbmax && allbrightup==0) {allbrightup=1;} if (allbright <=allbmin && allbrightup==1) {allbrightup=0;} if (allescc >allspeedc) {allescc=0; allcolor++;} if (allcolor > 255) {allcolor=0;} } void zufall(){ if(zufall1 > 75) {zufall1=random(0,40); zufall2=random(0,5); if(zufall2 ==0) {tudas[3]=random(0,1);} if(zufall2 ==1) {tudas[4]=random(0,1);} if(zufall2 ==2) {tudas[5]=random(0,3);}} tudas[0]=tudas[3]; tudas[1]=tudas[4]; tudas[2]=tudas[5]; } void links() { clickaction(0,4,180,250,nenrand);} void mitte() { clickaction(8,14,90,180,nenrand);} void rechts() { clickaction(4,8,0,90,nenrand); } void clickaction(int8_t ledvon,int8_t ledbis,int16_t rangemin, int16_t rangemax,int8_t dasda){ for( int bbb = ledvon; bbb < ledbis; bbb++) { if (dasda ==0) {leddata[bbb][7]=0; leddata[bbb][4]= random(rangemin,rangemax); leddata[bbb][0]=254; leddata[bbb][2]=random(2,7); } if (dasda ==1) {leddata[bbb][4]=rangemax; if ((flashing%2)==0) {leddata[bbb][0]=254;} if ((flashing%2)==1) {leddata[bbb][0]=0;}} if (dasda ==2) { if ((flashing%2)==0) {leddata[bbb][0]=254; leddata[bbb][6]=0; } if ((flashing%2)==1) {leddata[bbb][0]=0;}} }} void apply(){ for( int iy = 0; iy < screeny; iy++) { leds[iy] = ColorFromPalette( currentPalette, leddata[iy][4], leddata[iy][0], currentBlending);} FastLED.show(); FastLED.delay(1000 / 5000); } /**13x WS2812B or WS2812 controllcode by marderchen =^.^= used vor mouse illumilightly.. connected 3 moustasters to PA0-2 * (the stasters witching the 2V comes out frome optical module to ground so bridge PA0-2 to 3V3 if no tasters or remove or replace istinput(); with zufall(); in loop) * (4WS2812 first 4 one right, 4-8 left, 8-13 middle, fist led right near wire, last led wheel(layed in spiral) * required capacitor for stabilize power (have used 6.3V 1500yF for 5V and 6.3 1000yF on 3V3 on STMF103C8T6 (the on 3V3 not realy needet, just for savety) * used mouse: PO2361 MAXXTER Gamming mouse caused 6buttons , cheap with <5euro, and transparent part in case.. soldered out milky red fadingleds, and connectet STM to * BLACK (ground) and RED (+5V) wire from USB cable, and 3wires to the 3 taster (caused ground is same) cant use the other 3 taster caused switching not direct 5V od GND * ITs free! ( copy parts or use it in any kind if its usefull for you ) * ___ * _.-| | / |\__/,| (`\ { | | -- |^ ^ |__ _) ) "-.|___| \ _.( Y ) ` / .--'-`-. _((_ `^--' /__< \ ....-+|______|__.-||__)`-' (((/ (((/ CATS are awesome! */