Update extras.ino
This commit is contained in:
parent
846dc5edd4
commit
b141a83630
|
|
@ -2,124 +2,11 @@
|
||||||
|
|
||||||
#include "Pixel.h"
|
#include "Pixel.h"
|
||||||
|
|
||||||
struct Effect1 {
|
//#define PixelType Pixel
|
||||||
|
#define PixelType Dot
|
||||||
|
|
||||||
Pixel *px;
|
//Pixel p(8);
|
||||||
int H=0;
|
Dot p(0,1);
|
||||||
uint32_t alarmTime=0;
|
|
||||||
uint32_t speed;
|
|
||||||
uint8_t nPixels;
|
|
||||||
Pixel::Color c;
|
|
||||||
|
|
||||||
Effect1(Pixel *px, uint32_t speed, uint8_t nPixels){
|
|
||||||
this->px=px;
|
|
||||||
this->nPixels=nPixels;
|
|
||||||
this->speed=speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
void update(){
|
|
||||||
if(millis()<alarmTime)
|
|
||||||
return;
|
|
||||||
|
|
||||||
px->set(c.HSV(H,100,10),nPixels);
|
|
||||||
H=(H+1)%360;
|
|
||||||
|
|
||||||
alarmTime=millis()+speed;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Effect2 {
|
|
||||||
|
|
||||||
Pixel *px;
|
|
||||||
int phase=0;
|
|
||||||
int dir=1;
|
|
||||||
int H=0;
|
|
||||||
Pixel::Color x[60];
|
|
||||||
uint32_t alarmTime=0;
|
|
||||||
uint32_t speed;
|
|
||||||
uint8_t nPixels;
|
|
||||||
|
|
||||||
Effect2(Pixel *px, uint32_t speed, uint8_t nPixels){
|
|
||||||
this->px=px;
|
|
||||||
this->nPixels=nPixels;
|
|
||||||
this->speed=speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
void update(){
|
|
||||||
if(millis()<alarmTime)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for(int i=0;i<nPixels;i++){
|
|
||||||
if(i==phase)
|
|
||||||
x[i].HSV(H,100,100);
|
|
||||||
else if(i==nPixels-1-phase)
|
|
||||||
x[i].HSV(H+180,100,100);
|
|
||||||
else
|
|
||||||
x[i].RGB(0,0,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
px->set(x,nPixels);
|
|
||||||
phase=(phase+dir)%nPixels;
|
|
||||||
|
|
||||||
if(phase==0){
|
|
||||||
dir=1;
|
|
||||||
H=(H+10)%360;
|
|
||||||
}
|
|
||||||
else if(phase==nPixels-1){
|
|
||||||
dir=-1;
|
|
||||||
H=(H+10)%360;
|
|
||||||
}
|
|
||||||
|
|
||||||
alarmTime=millis()+speed;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Effect3 {
|
|
||||||
|
|
||||||
Dot *dot;
|
|
||||||
int H=0;
|
|
||||||
uint32_t alarmTime=0;
|
|
||||||
uint32_t speed;
|
|
||||||
uint8_t nPixels;
|
|
||||||
Dot::Color c;
|
|
||||||
|
|
||||||
Effect3(Dot *dot, uint32_t speed, uint8_t nPixels){
|
|
||||||
this->dot=dot;
|
|
||||||
this->nPixels=nPixels;
|
|
||||||
this->speed=speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
void update(){
|
|
||||||
if(millis()<alarmTime)
|
|
||||||
return;
|
|
||||||
|
|
||||||
dot->set(c.HSV(H,100,100),nPixels);
|
|
||||||
H=(H+1)%360;
|
|
||||||
|
|
||||||
alarmTime=millis()+speed;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#if defined(CONFIG_IDF_TARGET_ESP32C3)
|
|
||||||
|
|
||||||
Pixel px1(8); // NeoPixel RGB
|
|
||||||
Pixel px2(9,true); // NeoPixel RGBW
|
|
||||||
Dot dot(2,3); // DotStar
|
|
||||||
Pixel neo(0);
|
|
||||||
|
|
||||||
#elif defined(CONFIG_IDF_TARGET_ESP32)
|
|
||||||
|
|
||||||
// Pixel px1(23,true); // NeoPixel RGB
|
|
||||||
// Dot dot(32,5); // DotStar
|
|
||||||
Pixel px2(21); // NeoPixel RGBW
|
|
||||||
Pixel neo(26);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//Effect1 effect1(&px1,20,60);
|
|
||||||
//Effect2 effect2(&px2,20,60);
|
|
||||||
//Effect2 effect2(&px1,20,60);
|
|
||||||
//Effect3 effect3(&dot,20,30);
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
|
|
@ -129,21 +16,27 @@ void setup() {
|
||||||
|
|
||||||
Serial.println("\n\nHomeSpan Pixel Example\n");
|
Serial.println("\n\nHomeSpan Pixel Example\n");
|
||||||
|
|
||||||
Pixel::Color c;
|
PixelType::Color off=PixelType::RGB(0,0,0);
|
||||||
int hue=0;
|
|
||||||
|
|
||||||
// Pixel px2(21); // NeoPixel RGBW
|
p.set(PixelType::RGB(0,0,255),3);
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
while(1){
|
p.set(off,3);
|
||||||
neo.set(c.HSV(hue,100,10),8);
|
delay(1000);
|
||||||
hue=(hue+10)%360;
|
|
||||||
delay(100);
|
PixelType::Color c[]={p.HSV(120,100,30),p.HSV(0,0,0),p.HSV(0,0,0)};
|
||||||
}
|
p.set(c,3);
|
||||||
|
delay(1000);
|
||||||
} // end of setup()
|
|
||||||
|
c[0].HSV(0,0,0);
|
||||||
|
c[1].HSV(60,100,30);
|
||||||
|
p.set(c,3);
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
|
c[1].HSV(0,0,0);
|
||||||
|
c[2].HSV(0,100,30);
|
||||||
|
p.set(c,3);
|
||||||
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
// effect1.update();
|
|
||||||
// effect2.update();
|
|
||||||
// effect3.update();
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue