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

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

data structure

const uint8_t anim[] = {
  0x00, 0x8F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x04, 0x0E, 0x19, 0x22, 0x22, 0x17, 0x09, 0x01, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x0D, 0x40, 0x99, 0xF2, 0xFF, 0xFF, 0xF4, 0x91, 0x38, 0x0B, 0x01,
  0x00, 0x00, 0x00, 0x16, 0x6B, 0xC6, 0xE5, 0xDB, 0xCF, 0xBC, 0x93, 0x4B,
  0x13, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x48, 0xB4, 0xC8, 0xBC, 0xBA,
  0xB8, 0xAD, 0x8A, 0x42, 0x0E, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x0C, 0x40, 0x9D, 0xF4, 0xFF, 0xFF, 0xFF, 0xDB, 0x70, 0x24, 0x06, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x09, 0x19, 0x26, 0x2C, 0x29,
  0x1D, 0x0F, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00

.............................

Files at this revision

API Documentation at this revision

Comitter:
cdupaty
Date:
Tue Oct 05 15:30:40 2021 +0000
Parent:
0:eb53bdf2b7eb
Commit message:
more comments to understand the program

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Oct 05 13:33:00 2021 +0000
+++ b/main.cpp	Tue Oct 05 15:30:40 2021 +0000
@@ -1,21 +1,3 @@
-#include "mbed.h"
-
-//--------------------------------------------------------------------------
-// Animated flame for Adafruit Pro Trinket.  Uses the following parts:
-//   - Pro Trinket microcontroller (adafruit.com/product/2010 or 2000)
-//     (#2010 = 3V/12MHz for longest battery life, but 5V/16MHz works OK)
-//   - Charlieplex LED Matrix Driver (2946)
-//   - Charlieplex LED Matrix (2947, 2948, 2972, 2973 or 2974)
-//   - 350 mAh LiPoly battery (2750)
-//   - LiPoly backpack (2124)
-//   - SPDT Slide Switch (805)
-//
-// This is NOT good "learn from" code for the IS31FL3731; it is "squeeze
-// every last byte from the Pro Trinket" code.  If you're starting out,
-// download the Adafruit_IS31FL3731 and Adafruit_GFX libraries, which
-// provide functions for drawing pixels, lines, etc.  This sketch also
-// uses some ATmega-specific tricks and will not run as-is on other chips.
-//--------------------------------------------------------------------------
 /*
 Christian Dupaty 10/2021
 IS31FL3731 with CHARLEPLEX LED MATRIX adaptation from Adafruit project to ARM MBEB, tested on NUCLEO L073RZ
@@ -35,8 +17,26 @@
 ex: Wire.write (I2C_ADDR, cmd, s); I2C_ADDR address on 8bits, cmd pointer to data to send, s number of data
 */
 
+//--------------------------------------------------------------------------
+// Animated flame for Adafruit Pro Trinket.  Uses the following parts:
+//   - Pro Trinket microcontroller (adafruit.com/product/2010 or 2000)
+//     (#2010 = 3V/12MHz for longest battery life, but 5V/16MHz works OK)
+//   - Charlieplex LED Matrix Driver (2946)
+//   - Charlieplex LED Matrix (2947, 2948, 2972, 2973 or 2974)
+//   - 350 mAh LiPoly battery (2750)
+//   - LiPoly backpack (2124)
+//   - SPDT Slide Switch (805)
+//
+// This is NOT good "learn from" code for the IS31FL3731; it is "squeeze
+// every last byte from the Pro Trinket" code.  If you're starting out,
+// download the Adafruit_IS31FL3731 and Adafruit_GFX libraries, which
+// provide functions for drawing pixels, lines, etc.  This sketch also
+// uses some ATmega-specific tricks and will not run as-is on other chips.
+//--------------------------------------------------------------------------
+
+#include "mbed.h"
 #include "data.h"           // Flame animation data
-//#define debug
+//#define debug             // for some printf
 #define I2C_ADDR 0xE8       // I2C address of Charlieplex matrix 0x74
 I2C Wire(I2C_SDA, I2C_SCL);
 uint8_t        page = 0;    // Front/back buffer control
@@ -60,10 +60,10 @@
 {
     uint8_t i, p, s;
 
-    s=0;
+    s=0;                // s is a counter for I2C buffer (cmd) write method
     pageSelect(0x0B);               // Access to the Function Registers (page Night)
-    cmd[0]=0;  
-    s++;                     // adress first internal register                    
+    cmd[0]=0;            // adress first internal register 
+    s++;                                       
     for(i=0; i<=0x0C; i++) 
     {
         cmd[i+1]=0x00;
@@ -149,13 +149,17 @@
             #endif
     }
     Wire.write(I2C_ADDR,cmd,s);
-    wait_ms(30);
+    wait_ms(30);            // can be adjuted for speed annimation
 }
 
 int main()
 {
-    //printf("Simulation flame with IS31FL3731\n\n");
+    #ifdef debug
+    printf("-------------------------------------------------------------\n");
+    printf("printf("Simulation flame with IS31FL3731\n\n");
+    printf("-------------------------------------------------------------\n");
+    #endif
+    // arduino like
     setup();
-    
-    while(1) loop();;
+    while(1) loop();
 }