A NodeMCU library to write to MAX7219 8x8 matrix displays using SPI
Based on https://github.com/marcelstoer/nodemcu-max7219
max7219 = require("max7219_8x8")
max7219 = nil
package.loaded["max7219_8x8"]=nil
Setting the parameters of led matrix.
config: a table with parameters:
- slaveSelectPin: number of pin which is connected to CS of the MAX7219
- numberOfModules: count of connected modules
- intensity: bright value (1 - 15)
- rotate: rotate all sprites on draw. Avalable values are "none" and "left". Default value is "none"
- drawMode: mode of draw sprites/ Available values are "mix" (bitwize OR) and "replace". Default value is "replace"
nil
max7219.setup({
numberOfModules = 4,
slaveSelectPin = 8,
intensity = 1,
rotate = "left",
drawMode = "mix"
})
Clear buffer
nil
nil
max7219.clear()
Fill buffer to on all leds
nil
nil
max7219.fill()
Turn off led panel, but save state leds.
nil
nil
max7219.turn_off()
Turn on led panel. Setup call this function
nil
nil
max7219.turn_on()
Draw one sprite 8x8 in buffer
- x - horizontal coordinate
- y - vertical coordinate (now not work, reserved)
- bytes - table of 8 bytes
- rotate - not required parameter, can overwrite global settings
nil
a = { 0x20, 0x74, 0x54, 0x54, 0x3C, 0x78, 0x40, 0x00 }
b = { 0x41, 0x7F, 0x3F, 0x48, 0x48, 0x78, 0x30, 0x00 }
c = { 0x38, 0x7C, 0x44, 0x44, 0x6C, 0x28, 0x00, 0x00 }
d = { 0x30, 0x78, 0x48, 0x49, 0x3F, 0x7F, 0x40, 0x00 }
max7219.draw_sprite(0, 0, a)
max7219.draw_sprite(8, 0, b)
max7219.draw_sprite(16, 0, c)
max7219.draw_sprite(24, 0, d)
Set pixel on or off
- x - horizontal coordinate
- y - vertical coordinate
- value - integer variable. Use 0 if you want off pixel, or any other value if you want on pixel
nil
max7219.set_pixel(0, 0, 1) -- on
max7219.set_pixel(0, 0, 0) -- off
Set bright of panel
- value - bright value (1 - 15)
nil
max7219.set_intensity(5)
Send image from buffer to led matrix
nil
nil
max7219.update()
max7219 = require("max7219_8x8")
max7219.setup({
numberOfModules = 4,
slaveSelectPin = 8,
intensity = 1,
rotate = "left",
drawMode = "mix"
})
max7219.clear()
a = { 0x20, 0x74, 0x54, 0x54, 0x3C, 0x78, 0x40, 0x00 }
b = { 0x41, 0x7F, 0x3F, 0x48, 0x48, 0x78, 0x30, 0x00 }
c = { 0x38, 0x7C, 0x44, 0x44, 0x6C, 0x28, 0x00, 0x00 }
d = { 0x30, 0x78, 0x48, 0x49, 0x3F, 0x7F, 0x40, 0x00 }
max7219.draw_sprite(0, 0, a)
max7219.draw_sprite(8, 0, b)
max7219.draw_sprite(16, 0, c)
max7219.draw_sprite(24, 0, d)
max7219.update()