Skip to content

Instantly share code, notes, and snippets.

@hpwit
Last active December 26, 2022 12:11
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/405cb2af0e9b52862ac7bf85e207babf to your computer and use it in GitHub Desktop.
Save hpwit/405cb2af0e9b52862ac7bf85e207babf to your computer and use it in GitHub Desktop.
#include <FastLED.h>
struct UDS56503
{
uint32_t valuel ;
uint8_t valueh ;
inline UDS56503() __attribute__((always_inline))
{}
inline UDS56503(uint32_t vl, uint8_t vh ) __attribute__((always_inline))
{
valuel=vl;
valueh=vh;
}
inline UDS56503 (const UDS56503& rhs) __attribute__((always_inline))
{
valuel=rhs.valuel;
valueh=rhs.valueh;
}
inline UDS56503( uint32_t ir, uint32_t ig, uint32_t ib) __attribute__((always_inline))
{
//((ir<<20) & 0xFFF00000) + ((ig<<8) & 0x000FFF00) +
valuel=((ir<<20) & 0xFFF00000) + ((ig<<8) & 0x000FFF00) + ((ib) & 0xFF);
// printf("%x %x %x %x\n",ib,(ib>>4),((ib>>4) & 0xFF),valuel);
valueh=((ib>>8) & 0xF) ;
}
inline UDS56503 &operator= (const CRGB& rhs) __attribute__((always_inline))
{
valuel=(( (rhs.r<<4)<<20) & 0xFFF00000) + (( (rhs.g<<4)<<8) & 0x000FFF00) + (( (rhs.b<<4)) & 0xFF);
// printf("%x %x %x %x\n",ib,(ib>>4),((ib>>4) & 0xFF),valuel);
valueh=(( (rhs.b<<4)>>8) & 0xF) ;
return *this;
}
};
class UDS56503STRIP
{
public:
CRGB * _leds;
inline UDS56503STRIP(CRGB * leds) __attribute__((always_inline)) {
_leds=leds;
}
void setLed(int pos,UDS56503 led)
{
//get the CRGB led numbeo
int lednum=(pos*36)/24;
int decal=pos*36-lednum*24;
printf("cal %d %d\n",lednum,decal);
if(decal ==0)
{
*((uint32_t *) (_leds+lednum))=((led.valuel & 0xFF000000)>>24) + ((led.valuel & 0x00F00000)>>8)+ ((led.valuel & 0x0F0000) >>8) + ((led.valuel & 0x00FF00)<<8 ) +((led.valuel & 0x000F0)<<20 )+ ((led.valueh & 0xf)<<28);//+((led.valuel & 0x000FF)<<24);
*(((uint8_t *) (_leds+lednum))+4) = ((led.valuel & 0xf)<<4) + (*(((uint8_t *) (_leds+lednum))+4)& 0x0F);
}
else
{
*((uint32_t *) (_leds+lednum))=((led.valuel & 0xF0000000)>>20) +(*((uint32_t *) (_leds+lednum)) & 0xF0FF)+((led.valuel & 0x0FF00000)>>4)+((led.valuel & 0x00FF000)<<12);
*(((uint16_t *) (_leds+lednum))+2) =((led.valuel & 0xF00) >>4) + (led.valueh ) +((led.valuel & 0xFF) <<8);
// printf(" \nval:%04x %x\n",((led.valuel & 0xF0000) >>16) + ((led.valuel & 0xFF) <<4) +(led.valueh >>8) ,led.valueh );
}
}
};
#define NUM_LEDS 100
#define DATA_PIN 3
#define NUM_LEDS_REAL (((NUM_LEDS * 36)/24) +1)
CRGB leds[NUM_LEDS_REAL];
UDS56503STRIP strip=UDS56503STRIP(leds);
void setup() {
// put your setup code here, to run once:
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS_REAL);
}
int off;
void loop() {
// put your main code here, to run repeatedly:
memset(leds,0,NUM_LEDS_REAL*3);
for(int i=0;i<NUM_LEDS;i++)
{
CRGB pix=CHSV(i,255,255);
UDS56503 pixel= UDS56503(pix.r<<4,pix.g<<4,pix.b<<4);
// UDS56503 pixel= UDS56503(1454,748,478);
strip.setLed((i+off)%NUM_LEDS,pixel);
}
FastLED.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment