Christian Dupaty 10/2021 IS31FL3731 with CHARLEPLEX LED MATRIX adaptation from Adafruit project to ARM MBEB, tested on NUCLEO L073RZ for original project on Arduino see https://learn.adafruit.com/animated-flame-pendant/overview

Dependencies:   mbed

You are viewing an older revision! See the latest version

Homepage

Christian Dupaty 10/2021

IS31FL3731 with CHARLIEPLEX LED MATRIX adaptation from Adafruit project to ARM MBEB, tested on NUCLEO L073RZ

for original project on Arduino see https://learn.adafruit.com/animated-flame-pendant/overview

The program reads the data from an images file and places it alternately on pages 0 and 1 of IS31FL3731

Data structure in data.h :

first byte x1 PF and y1 pf, second byte x2 PF and y2 pf

loop from x1 to x2

loop from y1 to y2

copy from the third byte into the img buffer (144 bytes)

https://os.mbed.com/media/uploads/cdupaty/stm32_flame.jpg

void loop()
{
    uint8_t  a, x1, y1, x2, y2, x, y,s;
#ifdef debug
    printf("-------------------------------------------------------------\n");
    printf("start loop\n");
    printf("-------------------------------------------------------------\n");
#endif
    pageSelect(0x0B);    // Function registers
    cmd[0]=0x01; // Picture Display reg
    cmd[1]=page;
    Wire.write(I2C_ADDR,cmd,2);

    page ^= 1; // Flip front/back buffer index

    // Then render NEXT frame.  Start by getting bounding rect for new frame:
    a = *ptr++;     // New frame X1/Y1
    if(a >= 144)   // 0x90
    {
        // EOD marker? (valid X1 never exceeds 8)
        ptr = anim;                 // Reset animation data pointer to start
        a   = *ptr++; // and take first value
    }
    x1 = a >> 4;                  // X1 = high 4 bits
    y1 = a & 0x0F;                // Y1 = low 4 bits
    a  = *ptr++;                // New frame X2/Y2
    x2 = a >> 4;                  // X2 = high 4 bits
    y2 = a & 0x0F;                // Y2 = low 4 bits

    // Read rectangle of data from anim[] into portion of img[] buffer
    #ifdef debug
    printf("x1= %d y1= %d x2= %d y2 = %d \n",x1,y1,x2,y2);
    #endif
    for(x=x1; x<=x2; x++) {
        // Column-major
        for(y=y1; y<=y2; y++) 
        {
        img[(x << 4) + y] = *ptr++;
        #ifdef debug
        printf("x= %d y= %d data= %d \n",x,y,img[(x << 4) + y]);
        #endif
        }
    }

    // Write img[] to matrix (not actually displayed until next pass)
    pageSelect(page);    // Select background buffer
    s=0;
    cmd[0]=0x24; // First byte of PWM data
    s++;
    // copy img buffer to IS31FL3731
    for(uint8_t j=0; j<144; j++) 
    {
            cmd[j+1]=img[j];
            s++;
            #ifdef debug
            printf("j= %d img[j]= %d \n",j,img[j]);
            #endif
    }
    Wire.write(I2C_ADDR,cmd,s);
    wait_ms(30);            // can be adjuted for speed annimation
}

All wikipages