Last active
June 9, 2016 19:35
-
-
Save marcelstoer/63f138f47f765e602a64 to your computer and use it in GitHub Desktop.
Moody: NodeMCU with MAX7219 8x8 matrix display (SPI)
This file contains 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
MAX7219_REG_NOOP = 0x00 | |
MAX7219_REG_DECODEMODE = 0x09 | |
MAX7219_REG_INTENSITY = 0x0A | |
MAX7219_REG_SCANLIMIT = 0x0B | |
MAX7219_REG_SHUTDOWN = 0x0C | |
MAX7219_REG_DISPLAYTEST = 0x0F | |
happy = {0x3C, 0x42, 0xA5, 0x81, 0xA5, 0x99, 0x42, 0x3C} | |
frown = {0x3C, 0x42, 0xA5, 0x81, 0xBD, 0x81, 0x42, 0x3C} | |
sad = {0x3C, 0x42, 0xA5, 0x81, 0x99, 0xA5, 0x42, 0x3C} | |
faces = {happy, frown, sad} | |
function sendByte(reg, data) | |
spi.send(1,reg * 256 + data) | |
tmr.delay(50) | |
end | |
function displayFace(faceIndex) | |
local face = faces[faceIndex] | |
-- iterates over all 8 columns and sets their values | |
for i=1,8 do | |
sendByte(i,face[i]) | |
end | |
end | |
function setup() | |
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 16, 8) | |
sendByte (MAX7219_REG_SHUTDOWN, 1) | |
sendByte (MAX7219_REG_SCANLIMIT, 7) | |
sendByte (MAX7219_REG_DECODEMODE, 0x00) | |
sendByte (MAX7219_REG_DISPLAYTEST, 0) | |
sendByte (MAX7219_REG_INTENSITY, 9) | |
sendByte (MAX7219_REG_SHUTDOWN, 1) | |
tmr.stop(0) | |
end | |
-- changes the face every two seconds cycling through the array of faces | |
function moody(i) | |
faceIndex = (i % 3) + 1 | |
displayFace(faceIndex) | |
tmr.alarm(0, 2000, 0, function() | |
moody(faceIndex) | |
end); | |
end | |
setup() | |
moody(0) |
@pentahertz I don't know i.e. I never implemented that. See this nodemcu/nodemcu-firmware#50 (comment) and http://nodemcu.readthedocs.org/en/dev/en/modules/spi/#spiset_mosi for reference. It might also be helpful to see how the Arduino lib https://github.com/squix78/MAX7219LedMatrix implemented that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
howto use 2 max7219 thanks