I have seen quite a few projects with LED matrices, specially the Pixel V2 or the GameFrame and the QR clock. All these projects are quite impressive, each offering something a bit different. My idea is to make a bit of each while keeping things simple and cost down, the total was around 100$.
- Like for the LED cube I made last year, I wanted an interactive drawing system where my son can paint in Processing and pass the pixel data through the Serial interface.
- In addition I tried to separate each LED to have a "cleaner" lighting; I removed the matrix front panel and replaced it by a laser cut grid. This gives the "square" look of Pixels we are familiar with. Then I covered the grid with two sheets of tracing paper to "blur" the lights (if someone has a better idea, please...)
- Since the Arduino library made by Adafruit does not work with the Teensy at the momen; I first wrote a code which helped me understand the working of the matrix but was two slow and flickered a lot. Then I found the code Markus Lipp published, thanks again. After a few tweaks, here is a simple sketch which will display an image and allow to change the color of each LED with a Serial message. With some additions, the code can also display animations from Serial or an SD card at 24bit colors and with a good frameRate.

Here is a Sketch for the Teensy 3 or 3.1. I use some pins which are underneath for the matrix, so that I still have the SPI pins for an SD card and Serial 2 to play with Bluetooth. If you want to use this code with the top pins only, you can change PORTB to PORTC.
- Like for the LED cube I made last year, I wanted an interactive drawing system where my son can paint in Processing and pass the pixel data through the Serial interface.
- In addition I tried to separate each LED to have a "cleaner" lighting; I removed the matrix front panel and replaced it by a laser cut grid. This gives the "square" look of Pixels we are familiar with. Then I covered the grid with two sheets of tracing paper to "blur" the lights (if someone has a better idea, please...)
- Since the Arduino library made by Adafruit does not work with the Teensy at the momen; I first wrote a code which helped me understand the working of the matrix but was two slow and flickered a lot. Then I found the code Markus Lipp published, thanks again. After a few tweaks, here is a simple sketch which will display an image and allow to change the color of each LED with a Serial message. With some additions, the code can also display animations from Serial or an SD card at 24bit colors and with a good frameRate.
Can you read this QR code? I am using the QRduino library to generate QR codes. With the Teensy RTC capability it is possible to make a fun clock! |
Here is a Sketch for the Teensy 3 or 3.1. I use some pins which are underneath for the matrix, so that I still have the SPI pins for an SD card and Serial 2 to play with Bluetooth. If you want to use this code with the top pins only, you can change PORTB to PORTC.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Modified by Frederic Drago to display a panel using 24 bits hex colors and gamma correction | |
* Modified by Markus Lipp adding interleaved buffers, streaming, 32x32 & 24bit support | |
* Based on "_16x32_Matrix R3.0" by Creater Alex Medeiros, http://PenguinTech.tk | |
* Use code freely and distort its contents as much as you want, just remeber to thank the | |
* original creaters of the code by leaving their information in the header. :) | |
*/ | |
//PortA[4:5, 12:13] = {33, 24, 3, 4} | |
//PortB[0:3, 16:19] = {16, 17, 19, 18, 0, 1, 32, 25} | |
//PortC[0:11] = {15, 22, 23, 9, 10, 13, 11, 12, 28, 27, 29, 30} | |
//PortD[0:7] = {2, 14, 7, 8, 6, 20, 21, 5} | |
//PortE[0:1] = {31, 26} | |
// Define pins (if you cannot use portB, since pin 32 is not available by default on the Teensy, portC must be used, | |
// then change also GPIOB to GPIOC in the code. | |
const uint8_t | |
//PortC | |
//APIN = 15, BPIN = 22, CPIN = 23, DPIN = 9, CLOCKPIN = 10, LATCHPIN = 13, OEPIN = 11, | |
//PortB | |
APIN = 16, BPIN = 17, CPIN = 19, DPIN = 18, CLOCKPIN = 0, LATCHPIN = 1, OEPIN = 32, | |
//PortD | |
R1PIN = 2, R2PIN = 8, | |
G1PIN = 14, G2PIN = 6, | |
B1PIN = 7, B2PIN = 20; | |
uint8_t pinTable[13] = { | |
R1PIN,R2PIN,G1PIN,G2PIN,B1PIN,B2PIN, | |
APIN,BPIN,CPIN,DPIN,CLOCKPIN,LATCHPIN,OEPIN}; | |
//Addresses 1/8 rows Through a decoder | |
uint16_t const A = 1, B = 2,C = 4, D=8; | |
//Acts like a 16 bit shift register | |
uint32_t const SCLK = 65536;//16 if using portC | |
uint32_t const LATCH = 131072;//32 if using portC | |
uint32_t const OE = 262144;//64 if using portC | |
uint16_t const abcVar[16] = { //Decoder counter var | |
// 0,A,B,A+B,C,C+A,C+B,A+B+C,0+D,A+D,B+D,A+B+D,C+D,C+A+D,C+B+D,A+B+C+D}; | |
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; | |
//Data Lines for row 1 red and row 9 red, ect. | |
uint16_t const RED1 = 1, RED2 = 8; | |
uint16_t const GREEN1 = 2, GREEN2 = 16; | |
uint16_t const BLUE1 = 4, BLUE2 = 32; | |
const uint8_t SIZEX = 32; | |
const uint8_t SIZEY = 32; | |
//BAM and interrupt variables | |
uint8_t rowN = 0; | |
uint16_t BAM; | |
uint8_t BAMMAX = 7; //now 24bit color! (0-7) | |
IntervalTimer timer1; | |
uint8_t gImage[1024][3]; | |
uint8_t gr, gg, gb; | |
uint8_t r, g, b; | |
char buffer[120]; | |
int bufidx = 0; | |
char c; | |
int i = 0; | |
int color = 0; | |
// -------------------------------- sample image to display by default ----------------------------------------------------- | |
static int hello[1024] = { | |
0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF, | |
0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0xFFFFFF, | |
0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000, | |
0xFFFFFF,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000, | |
0xFFFFFF,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000, | |
0xFFFFFF,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0x00000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000, | |
0x000000,0x000000,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFBA904,0xFBA904,0x000000,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xFBA904, | |
0xFBA904,0xFBA904,0xFBA904,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFBA904,0x000000,0xFFFFFF,0x000000,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0x000000,0xFFFFFF,0xFFFFFF,0x000000,0xFFFFFF,0xFFFFFF,0x000000,0x000000, | |
0xFBA904,0xFBA904,0xFBA904,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0x000000,0xFFFFFF,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000, | |
0xFBA904,0xFBA904,0xFBA904,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFBA904,0xFFFFFF,0x000000,0x000000,0xFFFFFF,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000, | |
0xFBA904,0xFBA904,0xFBA904,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFBA904,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0x000000,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000, | |
0x000000,0xFBA904,0xFBA904,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFBA904,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0x000000,0x000000,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0x000000, | |
0xFBA904,0xFBA904,0xFBA904,0x000000,0x000000,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904, | |
0xFBA904,0xFBA904,0x000000,0x000000,0xFBA904,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFBA904,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904, | |
0xFBA904,0xFBA904,0x000000,0xFBA904,0xFBA904,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFBA904,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904, | |
0xFBA904,0x000000,0xFBA904,0xFBA904,0xFBA904,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0x000000,0x000000,0x000000,0x000000,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904, | |
0xFBA904,0x000000,0xFBA904,0xFBA904,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904, | |
0xFBA904,0xFBA904,0xFBA904,0x000000,0xFBA904,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904, | |
0xFBA904,0xFBA904,0x000000,0xFBA904,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904, | |
0xFBA904,0xFBA904,0x000000,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904, | |
0xFBA904,0xFBA904,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0x000000,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904, | |
0xFBA904,0x000000,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFBA904,0xFBA904,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904, | |
0xFBA904,0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0x000000, | |
0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0x000000,0x000000,0x000000, | |
0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0x000000,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0xFBA904,0x000000,0x000000,0xFFFFFF,0xFFFFFF, | |
0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xFFFFFF,0xFFFFFF, | |
0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFC02B5,0xFC02B5,0xFC02B5,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFB0412,0xFB0412,0xFB0412,0xFFFFFF,0x000000,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0x000000, | |
0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFC02B5,0xF7FB04,0xF7FB04,0xF7FB04,0xFC02B5,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFB0412,0xF7FB04,0xF7FB04,0xF7FB04,0x000000,0x000000,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0x000000, | |
0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFC02B5,0xF7FB04,0xF7FB04,0xF7FB04,0xFC02B5,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFB0412,0xF7FB04,0xF7FB04,0xF7FB04,0x000000,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412, | |
0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFC02B5,0x2AF60A,0xFC02B5,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFB0412,0x2AF60A,0xFB0412,0x000000,0xFB0412,0x000000,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0x000000,0xFB0412, | |
0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x2AF60A,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x2AF60A,0xFFFFFF,0x000000,0xFB0412,0x000000,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0x000000,0xFB0412, | |
0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x2AF60A,0xFFFFFF,0x2AF60A,0xFFFFFF,0x2AF60A,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x2AF60A,0x2AF60A,0x2AF60A,0x000000,0xFB0412,0x000000,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0xFB0412,0x000000,0xFB0412, | |
0x000000,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0x2AF60A,0x2AF60A,0x2AF60A,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF | |
}; | |
// ---------------------------------------------------------------------------------------------------------------------------------- | |
void setup() { | |
for(uint8_t i = 0; i < 13; i++){ | |
pinMode(pinTable[i], OUTPUT); | |
} | |
// Prepare a default image | |
for (int i = 0; i < 1024; i++) { | |
gammaCorrect(hello[i]); | |
gImage[i][0] = gr; | |
gImage[i][1] = gg; | |
gImage[i][2] = gb; | |
} | |
Serial.begin(250000); | |
timerInit(); | |
} | |
// ---------------------------------------------------------------------------------------------------------------------------------- | |
void loop() { | |
// Normal serial from USB | |
// format to change a led is c,led number, color in hexadecimal ex: c,0,FF00FF (will change the first led to magenta) | |
Serial.flush(); | |
if (Serial.available() > 0) { | |
c = (char)Serial.read(); | |
buffer[bufidx++] = c; | |
if (c == '\n') { | |
buffer[bufidx++] = '\n'; | |
bufidx = 0; | |
parseBuffer(); | |
//gammaCorrectRGB(r, g, b); // works but takes too much time (could use a table), implemented in processing anyway | |
gImage[i][0] = r; | |
gImage[i][1] = g; | |
gImage[i][2] = b; | |
} | |
} | |
} | |
// ---------------------------------------------------END LOOP---------------------------------------------------------------- | |
void timerInit() { | |
BAM = 0; | |
attackMatrix(); | |
} | |
//The updating matrix stuff happens here | |
//each pair of rows is taken through its BAM cycle | |
//then the rowNumber is increased and is done again | |
void attackMatrix() { | |
timer1.end(); | |
uint16_t portData; | |
portData = 0; // Clear data to enter | |
portData |= (abcVar[rowN])|OE; // abc, OE | |
portData &=~ LATCH; //LATCH LOW | |
GPIOB_PDOR = portData; // Write to Port | |
for(uint8_t i = 0; i < 32; i++){ | |
uint16_t row = (rowN<<5)+i; | |
uint16_t row16 = ((rowN+16)<<5)+i; | |
uint16_t tempC[6] = { //Prepare data in correct place | |
((gImage[row][0])<<1) , ((gImage[row16][0])<<4), //3 | |
((gImage[row][1])<<1), ((gImage[row16][1])<<4), //4 | |
(gImage[row][2]<<1), (gImage[row16][2])<<4 }; //6 | |
uint16_t allC =//Put OUTPUT data into temp variable | |
((tempC[0]>>BAM)&RED1)|((tempC[1]>>BAM)&RED2)| | |
((tempC[2]>>BAM)&GREEN1)|((tempC[3]>>BAM)&GREEN2)| | |
((tempC[4]>>BAM)&BLUE1)|((tempC[5]>>BAM)&BLUE2); | |
GPIOD_PDOR = (allC); // Transfer data | |
GPIOB_PDOR |= SCLK;// Clock HIGH | |
GPIOB_PDOR &=~ SCLK;// Clock LOW | |
} | |
GPIOB_PDOR |= LATCH;// Latch HIGH | |
GPIOB_PDOR &=~ OE;// OE LOW, Displays line | |
#define LOOPTIME 1 //trial&error to get both smooth gradients & little flicker | |
#define CALLOVERHEAD 1 | |
timer1.begin(attackMatrix,((LOOPTIME+CALLOVERHEAD)<<BAM)-CALLOVERHEAD); | |
if(BAM >= BAMMAX) { //Checks the BAM cycle for next time. | |
if(rowN == 15){ | |
rowN = 0; | |
} | |
else { | |
rowN ++; | |
} | |
BAM = 0; | |
} | |
else { | |
BAM ++; | |
} | |
} | |
// Choose appropriate gamma value by comparison with computer monitor | |
void gammaCorrect(int pixel) | |
{ | |
float gammaCorrect = 1.0 /0.28; | |
gr = uint8_t((255.0 * (pow(((pixel >> 16) & 0xFF) / 255.0, gammaCorrect)))); | |
gg = uint8_t((255.0 * (pow(((pixel >> 8) & 0xFF) / 255.0, gammaCorrect)))); | |
gb = uint8_t((255.0 * (pow((pixel & 0xFF) / 255.0, gammaCorrect)))); | |
// following gives the best color reproduction, however brightness is lost | |
// float gammaCorrect = 1.0 /0.45; | |
// gr = uint8_t((255.0 * (pow(((pixel >> 16) & 0xFF) / 255.0, gammaCorrect)))*0.33); | |
// gg = uint8_t((255.0 * (pow(((pixel >> 8) & 0xFF) / 255.0, gammaCorrect))))*0.33; | |
// gb = uint8_t((255.0 * (pow((pixel & 0xFF) / 255.0, gammaCorrect)))*0.15); | |
} | |
void gammaCorrectRGB(uint8_t r, uint8_t g, uint8_t b) | |
{ | |
float gammaCorrect = 1.0 /0.28; | |
gr = uint8_t((255.0 * (pow(r / 255.0, gammaCorrect)))); | |
gg = uint8_t((255.0 * (pow(g / 255.0, gammaCorrect)))); | |
gb = uint8_t((255.0 * (pow(b / 255.0, gammaCorrect)))); | |
} | |
void hexToColor(int pixel) | |
{ | |
gr = uint8_t((pixel >> 16) & 0xFF); | |
gg = uint8_t((pixel >> 8) & 0xFF); | |
gb = uint8_t(pixel & 0xFF); | |
} | |
void parseBuffer(void) | |
{ | |
char *parseptr; | |
if (strncmp(buffer,"C",1) == 0 || strncmp(buffer,"c",1) == 0){ | |
parseptr = strchr(buffer, ',')+1; | |
i = parsenumber(parseptr,0); | |
parseptr = strchr(parseptr, ',')+1; | |
r = parseHex(parseptr[0])* 16 + parseHex(parseptr[1]) ; | |
g = parseHex(parseptr[2])* 16 + parseHex(parseptr[3]) ; | |
b = parseHex(parseptr[4])* 16 + parseHex(parseptr[5]) ; | |
} | |
} | |
// Function to parse fixed point numbers (numdec=number of decimals) | |
long parsenumber(char *str,byte numdec) { | |
long d = 0; | |
byte ndec = 0; | |
while (str[0] != 0) { | |
if (str[0] == '.'){ | |
ndec = 1; | |
} | |
else { | |
if ((str[0] > '9') || (str[0] < '0')) | |
return d; | |
d *= 10; | |
d += str[0] - '0'; | |
if (ndec > 0) | |
ndec++; | |
if (ndec > numdec) // we reach the number of decimals... | |
return d; | |
} | |
str++; | |
} | |
return d; | |
} | |
byte parseHex(char c) { | |
if (c < '0') | |
return (0); | |
if (c <= '9') | |
return (c - '0'); | |
if (c < 'A') | |
return (0); | |
if (c <= 'F') | |
return ((c - 'A')+10); | |
} |
Hi Great project.Any more detail on how you created that diffuse look?
ReplyDeleteThanks for providing such a helpful information Very nice I like a lot of these topics, it was part of my area.
ReplyDeletevideo wall
Cool blog you got here and thank you for the valuable info.
ReplyDeleteVideowall
Thanks for sharing such interesting info with us. its very helpful to search a cord and adapters.
ReplyDelete7 Way Trailer Cord
Transfer Switch Power Cord
Great information mention in this post its all information is really informative for all users.
ReplyDeleteTwist Lock Adapter
That is really fantastic. Your work is really fascinating and creative. It is appealing to do such creative work on LED and your rates are also very affordable.
ReplyDeleteHow nice of your to provide this a deep information.Thank you so much.HDMI Cables
ReplyDeleteIt's a great blog! As a newcomer, this helps me learn everything very well. Thanks for sharing!
ReplyDeleteWeb Scraping & Data Mining Services
Web Scraping Services
Enterprise-Grade Web Crawling Service Provider
Data as a Service Provider
thanks for nice
ReplyDeletehttps://worldforpcapp.com/
Great Article, Looking for LED Panel Lights visit my website: rgb led panels
ReplyDelete