Now, let's hit some code that keeps the display showing what is in the display buffer. The initial approach is to have all pixel data in the buffer as well as the control data that does the multi-plex: picking the row. It leads to a bit less code, creates redundancy, uses memory... After all: it can be calculated while iterating through the data.
The code contains documentation about its pieces.
// ledMatrix9.js
// code exploring led matrix display w/ Espruino board
// Espruino-WiFi / Pico / Original / Puck
/*
Home made 'pricy' LED Matrix 3x5x1 w*h*c (c=color depth)
Basic operation:
- shift out columns of one row (padded/trailed to fill gap)
- shift out rows with only on row low (padded/trailed)
- /RCK latch (shows data) - automatically w/ dnss
*/
var dbuf = // display buffer, organized as rows.
// Set LEDs @ [0,0], [1,1], [2,4] Red on (top left LED,
// 2nd col of 2nd row and last/3rd col in last/5th row:
// col bits row bit
// .......2 22111000 ...43210
// color B GRBGRBGR drain
[ [0b00000000,0b00000001,0b11111110] // - row 0
, [0b00000000,0b00001000,0b11111101] // - row 1
, [0b00000000,0b00000000,0b11111011] // - row 2
, [0b00000000,0b00000000,0b11110111] // - row 3
, [0b00000000,0b01000000,0b11101111] // - row 4
];
var // connect definitions (Espruino -> 595 wiring):
// SPI1 and other GPIOs 74HC595 (pin)
dspiDat=B5 // a) SDA ser data MOSI -> SER (14)
, dspiClk=B3 // b) SCK ser clock -> SRCLK (11)
, dnss =A0 // c) NSS to go w/ SPI -> RCLK (12)
, dnoe =A1 // d) 595 output enable -> _OE (13)
; // e) 595 _clear fix 1 -> _SRCLR (10)
// A0 dnss is co-used for output register latch.
// Latch prevents blur while shifting.
// A1 can do PWM when danger of over powering LEDs.
pinMode(dspiDat, "output"); dspiDat.set();
pinMode(dspiClk, "output"); dspiClk.set();
pinMode(dnss , "output"); dnss.set();
pinMode(dnoe , "output"); dnoe.set();
SPI1.setup({ mosi: dspiDat, sck: dspiClk });
var rdx, iId // interval ID and interval time w/
, iTm = 4; // row event every 4 millisec to yield
// 50 times/sec refresh, 20% duty cycle
function r() { // run
dnoe.reset();
rdx = 4;
iId = setInterval(function(){
rdx = ++rdx % 5;
SPI1.write(dbuf[rdx],dnss);
}, iTm);
}
function h() { // halt
iId = clearInterval(iId);
dnoe.set();
}
setTimeout(r,100);
The function r() runs the example, function h() halts it.
Attached is a picture of the running display showing what is in display buffer of example.
Driving the 595 with higher voltage yields more brightness. To drive really large columns and rows, extra driver have to be used.
What we have achieved so far, is driving a LED matrix through 74HC595 shift register with data from a display buffer. Next step will be connecting Espruino Graphic Class with this 'display driver'.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Now, let's hit some code that keeps the display showing what is in the display buffer. The initial approach is to have all pixel data in the buffer as well as the control data that does the multi-plex: picking the row. It leads to a bit less code, creates redundancy, uses memory... After all: it can be calculated while iterating through the data.
The code contains documentation about its pieces.
The function
r()
runs the example, functionh()
halts it.Attached is a picture of the running display showing what is in display buffer of example.
Driving the 595 with higher voltage yields more brightness. To drive really large columns and rows, extra driver have to be used.
What we have achieved so far, is driving a LED matrix through 74HC595 shift register with data from a display buffer. Next step will be connecting Espruino Graphic Class with this 'display driver'.
To be continued...
1 Attachment