Skip to content

Instantly share code, notes, and snippets.

@hpwit
Created November 4, 2022 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hpwit/1ee1fff98cb511f1630ecb3bc73e9e5c to your computer and use it in GitHub Desktop.
Save hpwit/1ee1fff98cb511f1630ecb3bc73e9e5c to your computer and use it in GitHub Desktop.
#define FULL_DMA_BUFFER
#define USE_FASTLED
#define COLOR_GRB
#include "I2SClocklessLedDriver.h"
#define NUM_LEDS_PER_STRIP 256
#define NUMSTRIPS 3
//here we have 3 colors per pixel
//uint8_t leds[numstrips*ledsperstrip*3];
//this one below is same as the one above
CRGB leds[NUMSTRIPS*NUM_LEDS_PER_STRIP];
int pins[3]={0,2,4};
int lengths[3]={200,50,256};
Pixels ff=Pixels(lengths,NUMSTRIPS);
Pixels gg,kk,pp,pp2;
Pixels lines[16];
Pixels columns[16];
I2SClocklessLedDriver driver;
struct param
{
int col;
int off;
} f;
param dd={
5,0
};
param dd2={
6,0
};
int map(int i,void * df2)
{
//i=i%16;
param *df=(param*)df2;
//Serial.printf("%d %d \n",df->col,i);
if(i%2==0)
{
return i*16+df->col;
}
else
{
return i*16+(16-df->col-1);
}
}
int map2(int i,void * df2)
{
i=i%50;
param *df=(param*)df2;
int x1=15-i+df->col;
int y1=df->col;
if(x1 >=16 or y1>=16 or x1<0 or y1<0)
return _OUT_OF_BOUND;
//Serial.printf("%d %d \n",df->col,i);
if(x1%2==0)
{
return x1*16+y1;
}
else
{
return x1*16+(16-y1-1);
}
}
int map3(int i,void * df2)
{
i=i%50;
param *df=(param*)df2;
int x1=15-i+df->col;
int y1=df->col;
if(y1>8)
x1=15-i+(16-df->col);
if(x1 >=16 or y1>=16 or x1<0 or y1<0)
return _OUT_OF_BOUND;
//Serial.printf("%d %d \n",df->col,i);
if(y1%2==0)
{
return x1+y1*16;
}
else
{
return y1*16+(16-x1-1);
}
}
int map4(int i,void * df2)
{
if (i<0 or i>15)
return _OUT_OF_BOUND;
//i=i%30;
param *df=(param*)df2;
int x1=i;
int y1=i+df->col;
if(x1>=8)
y1=df->col-i+14;
if(x1 >=16 or y1>=16 or x1<0 or y1<0)
return _OUT_OF_BOUND;
//Serial.printf("%d %d \n",df->col,i);
if(y1%2==0)
{
return x1+y1*16;
}
else
{
return y1*16+(16-x1-1);
}
}
int map5(int i,void * df2)
{
param *df=(param*)df2;
i=i+df->off;
if (i<0 or i>15)
return _OUT_OF_BOUND;
//i=i%30;
// param *df=(param*)df2;
int x1=i;//+df->off;
int y1=floor(10*sin((i-df->off)*PI/2/15))+df->col;
if(x1 >=16 or y1>=16 or x1<0 or y1<0)
return _OUT_OF_BOUND;
//Serial.printf("%d %d \n",df->col,i);
if(y1%2==0)
{
return x1+y1*16;
}
else
{
return y1*16+(16-x1-1);
}
}
void setup() {
Serial.begin(115200);
//driver.initled(ff.getPixels(),pins,lengths,NUMSTRIPS);//,NUM_LEDS_PER_STRIP,ORDER_GRB);
//driver.setBrightness();
driver.initled(ff,pins);
driver.setBrightness(5);
// Serial.printf("nee %d\n",ff._num_strips);
gg=ff.getStrip(2).createSubset(32,50);
kk=ff.getStrip(2).createSubset(16,16);
Serial.printf("sss\n");
pp=ff.getStrip(2).createSubset(0,leddirection::MAP);
Serial.printf("ssccs\n");
pp.setMapFunction(map,&dd,sizeof(dd));
pp2=ff.getStrip(2).createSubset(0,leddirection::MAP);
pp2.setMapFunction(map, &dd2,sizeof(dd2));
for (int i=0;i<16;i++)
{
lines[i]=ff.getStrip(2).createSubset(i*16,16,i%2 ? leddirection::BACKWARD:leddirection::FORWARD);
columns[i]=ff.getStrip(2).createSubset(0,leddirection::MAP);
dd.col=i;
columns[i].setMapFunction(map5,&dd,sizeof(dd));
}
ff.getStrip(2)[0]=CRGB(255,0,0);
ff.getStrip(2)[1]=CRGB(255,0,0);
}
int A[]={
0, 1, 1, 1, 1, 0,
0, 1, 0, 1, 1, 0,
0, 1, 0, 1, 1, 0,
0, 1, 1, 1, 1, 0,
0, 1, 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 0, 1, 1, 0, 0,
0, 0, 1, 1, 0, 0,
0, 0, 1, 1, 0, 0,
0, 0, 1, 1, 0, 0,
0, 1, 1, 1, 1, 0
};
int J[]={
0, 1, 1, 1, 1, 0,
0, 1, 1, 0, 0, 0,
0, 1, 1, 0, 0, 0,
0, 1, 1, 0, 0, 0,
0, 1, 1, 0, 1, 0,
0, 1, 1, 0, 1, 0,
0, 0, 1, 1, 0, 0
};
int K[]={
0, 1, 0, 1, 1, 0,
0, 1, 0, 1, 1, 0,
0, 0, 1, 1, 1, 0,
0, 0, 0, 1, 1, 0,
0, 0, 1, 1, 1, 0,
0, 1, 0, 1, 1, 0,
0, 1, 0, 1, 1, 0
};
int L[]={
0, 0, 0, 1, 1, 0,
0, 0, 0, 1, 1, 0,
0, 0, 0, 1, 1, 0,
0, 0, 0, 1, 1, 0,
0, 0, 0, 1, 1, 0,
0, 0, 0, 1, 1, 0,
0, 1, 1, 1, 1, 0
};
int M[]={
1, 0, 0, 0, 1, 1,
1, 1, 0, 1, 1, 1,
1, 0, 1, 0, 1, 1,
1, 0, 0, 0, 1, 1,
1, 0, 0, 0, 1, 1,
1, 0, 0, 0, 1, 1,
1, 0, 0, 0, 1, 1,
};
int N[]={
1, 0, 0, 1, 1, 0,
1, 0, 0, 1, 1, 0,
1, 0, 1, 1, 1, 0,
1, 1, 0, 1, 1, 0,
1, 0, 0, 1, 1, 0,
1, 0, 0, 1, 1, 0,
1, 0, 0, 1, 1, 0,
};
int *t[]={A,B,C,D,E,F,G,H,I,J,K,L,M,N};
int off=0;
long time1,time2,time3;
void loop()
{
//columns[0][0]=CRGB(255,0,0);
// columns[2][0]=CRGB(255,0,0);
// for(int k=0;k<20;k++)
// {
time1=ESP.getCycleCount();
ff.clear();
for(int j=0;j<7;j++)
{
for(int i=0;i<6;i++)
{
// lines[2*j][off+i]=CRGB(255,255,0);
for(int k=0;k<2*sizeof(t)/sizeof(int);k++)
{
//if(10+i-off+k*8 >=0 and 10+i-off+k*8<16)
if( t[k%(sizeof(t)/sizeof(int))][(5-i)+6*(6-j)]==1)
// columns[j][(10+i-off+k*7)]=CRGB(255,0,255);
lines[j][(10+i-off+k*6)]=CRGB(255,255,0);
}
//pp[off+i]=CRGB( 255,0,255);
//pp2[off+i]=CRGB( 255,0,255);
}
/*
for(int i=0;i<6;i++)
{
// lines[2*j][off+i]=CRGB(255,255,0);
if( B[i+6*j]==1)
{
columns[(off+i+5)%16][j+8]=CRGB(255,0,255);
// lines[j+8][off+i+6]=CRGB(255,255,0);
}
//pp[off+i]=CRGB( 255,0,255);
//pp2[off+i]=CRGB( 255,0,255);
}
for(int i=0;i<6;i++)
{
// lines[2*j][off+i]=CRGB(255,255,0);
if( C[i+6*j]==1)
{
columns[(off+i)%16][j+8]=CRGB(255,0,255);
// lines[j+8][off+i+6]=CRGB(255,255,0);
}
//pp[off+i]=CRGB( 255,0,255);
//pp2[off+i]=CRGB( 255,0,255);
}
*/
//columns[2*j+1].copy(lines[2*j]);
//columns[2].copy(lines[0]);
for(int i=0;i<5;i++)
{
//lines[2*j][off+i]=CRGB(255,255,0);
// columns[2*j][off+i]=CRGB(255,0,255);
//pp[off+i]=CRGB( 255,0,255);
//pp2[off+i]=CRGB( 255,0,255);
//lines[2*j].clear();
}
}
// gg[off]=CRGB( 0,255,0);
// kk[off+1]=CRGB( 0,0,255);
// kk[off]=CRGB( 0,0,255);
//pp[off]=CRGB(255,0,255);
// kk->getParent()[5]=CRGB(255,0,255);
// Serial.printf("%d \n",ff.nb_child);
//Pixels * l=ff.getChild(1);
// (*l)[10]=CRGB(255,255,0);
//ff.getChild(0);
//d[3]=CRGB(0,255,255);
time2=ESP.getCycleCount();
//driver.showPixels();
//Serial.print("befor trasnspo\n");
//ff.getStrip(2)[0]=CRGB(255,0,0);
//ff.getStrip(2)[1]=CRGB(255,0,0);
driver.showPixelsFirstTranspose();
// delay(50);
time3=ESP.getCycleCount();
// Serial.printf("off :%d Calcul pixel fps:%.2f showPixels fps:%.2f Total fps:%.2f \n",off,(float)240000000/(time2-time1),(float)240000000/(time3-time2),(float)240000000/(time3-time1));
Serial.printf("on swith\n");
for (int i=0;i<16;i++)
{
//lines[i]=ff.getStrip(2).createSubset(i*16,16,i%2 ? leddirection::BACKWARD:leddirection::FORWARD);
//columns[i]=ff.getStrip(2).createSubset(0,leddirection::MAP);
dd.col=i;
dd.off=floor(10*cos((off)*PI/2/5));
columns[i].setMapFunction(map5,&dd,sizeof(dd));
}
Serial.printf("on a switché %d\n",dd.off);
off=(off+1)%250;
// Serial.printf("nonon\n");
// }
// vTaskDelete(NULL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment