 | Code: #include "HCWS2812.h"
HCWS2812 HCWS2812; int r,g,b; int x=0; int z=0; int o=0; int mode =0; int button; int latch=0; int ani=0; int counter =0;
byte R[]{255,255,0,0,0,255,255}; byte G[]{0,255,255,255,0,0,130}; byte B[]{0,0,0,255,255,255,0};
byte index;
byte invader[]={
0,255,255,255,255,0,0,0, 0,0,255,255,255,255,0,255, 255,255,255,0,255,255,255,0, 0,0,255,255,255,255,0,0, 0,0,255,255,255,255,0,0, 255,255,255,0,255,255,255,0, 0,0,255,255,255,255,0,255, 0,255,255,255,255,0,0,0,
};
byte invader2[]={
0,0,0,255,255,255,255,0, 0,0,255,255,255,255,0,0, 255,255,255,0,255,255,255,255, 0,0,255,255,255,255,0,0, 0,0,255,255,255,255,0,0, 255,255,255,0,255,255,255,255, 0,0,255,255,255,255,0,0, 0,0,0,255,255,255,255,0, };
byte invader3[]={ 0,255,255,255,255,0,0,0, 0,0,255,255,255,255,0,255, 255,255,255,0,255,255,255,0, 0,0,255,255,255,255,0,0, 0,0,255,255,255,255,0,0, 255,255,255,0,255,255,255,0, 0,0,255,255,255,255,0,255, 0,255,255,255,255,0,0,0 }; byte invader4[]={ 0,0,0,255,255,0,0,255, 0,0,255,255,255,0,255,0, 0,255,255,0,255,255,0,255, 255,255,255,255,255,0,255,0, 255,255,255,255,255,0,255,0, 0,255,255,0,255,255,0,255, 0,0,255,255,255,0,255,0, 0,0,0,255,255,0,0,255, };
void setup() { //Serial.begin(9600); pinMode(9,OUTPUT); pinMode(15,INPUT_PULLUP); HCWS2812.SetBG(0, 255, 0); }
void loop() {
button = digitalRead(15); if(button==LOW){mode++;latch=0; HCWS2812.ClearBuffer(); HCWS2812.Refresh(); delay(500); if(mode==5){mode=0;}
}
//*************************MODE 0 : Shuts off LEDS if(mode==0){ if(latch==0){ for(index = 0; index < 8; index++){ HCWS2812.SetBG(0,0,0); HCWS2812.SetFontBG(0, 0, 0); HCWS2812.SetFontFG(0, 0, 0); RGBBuffer[RED][index]=0; RGBBuffer[GREEN][index]=0; RGBBuffer[BLUE][index]=0; HCWS2812.ClearBuffer(); HCWS2812.Refresh(); latch=1; } } } //***************************************COUNT
if(mode==1){ x++; if(x==50){x=0; counter++;} if(counter==100){counter=0;} HCWS2812.SetBG(0, 0, 2); HCWS2812.SetFontBG(0, 0, 2); HCWS2812.SetFontFG(150, 50, 0); for(index = 0; index <16; index++){ HCWS2812.print(counter,index); HCWS2812.Refresh(); delayMicroseconds(350); } HCWS2812.ClearBuffer(); HCWS2812.Refresh(); delay(40); } //****************MODE 2 displays ARDUINO in colour arrays
if(mode==2){ HCWS2812.SetFontBG(0, 0, 2);HCWS2812.SetBG(0,0,2); HCWS2812.SetFontFG(200, 200, 0); for(index = 0; index <56; index++){ HCWS2812.print("Arduino", index); HCWS2812.SetFontFG(R[index/8],G[index/8],B[index/8]); HCWS2812.Refresh(); delayMicroseconds(100); } HCWS2812.ClearBuffer(); HCWS2812.Refresh(); delay(35); } //******************MODE 3 : space invaders animation
if(mode==3){ HCWS2812.SetBG(1, 0, 1); if(ani==6){ani=0;} if(ani<3){ vade0();} if(ani>=3){vade1();} } //******************MODE 4: prints LUKE
if(mode==4){ HCWS2812.SetBG(0, 0, 2); HCWS2812.SetFontBG(0, 0, 2); HCWS2812.SetFontFG(150, 50, 0); for(int test = 0; test <32; test++){ HCWS2812.print("LUKE",test); HCWS2812.Refresh(); delayMicroseconds(300); } HCWS2812.ClearBuffer(); HCWS2812.Refresh(); delay(70); }
//************************************ }
void vade0(){ for(int i=0;i<8;i++){ RGBBuffer[GREEN][i]=invader[z]; z++; } HCWS2812.Refresh(); delayMicroseconds(250); if(z==64){z=0;ani++; HCWS2812.ClearBuffer(); HCWS2812.Refresh(); delay(10);} }
void vade1(){ for(int i=0;i<8;i++){
RGBBuffer[GREEN][i]=invader2[o]; o++; } HCWS2812.Refresh(); delayMicroseconds(250); if(o==64){o=0;ani++; HCWS2812.ClearBuffer(); HCWS2812.Refresh(); delay(10);} }
|  |