Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By joeygbsn
#51541 Heres some simple code to drive a Max7219. The code just initializes the Max7219 and then you can use the textboxes to change the values on the display. The Max7219 is a 5V device, so I am powering it from the usb 5V available on Vin when using a microusb charger as a power supply. The datasheet does say that a logic high is 3.5V which is higher than the 3.3V the esp's MOSI pin delivers, but I have yet to see any errors in data transmitted. This code was written using V3.0 alpha 8.

Code: Select allspi.setup(500000) 'clk on gpio14(d5) mosi on gpio13(d7) load on gpio15(d8)

let load = 15
let digit1 = "01"
let digit2 = "02"
let digit3 = "03"
let digit4 = "04"
let n1 = "1"
let n2 = "2"
let n3 = "3"
let n4 = "4"
let count = 0
io(po,load,0)'set load pin low

print "Max7219 test program"
print
textbox n1
textbox n2
textbox n3
textbox n4
wprint "<br>"
print "Each box corresponds to a digit on the display. Valid inputs are 0-9 and a-f."

'initialize max7219
spi.hex("090F",2)   'decode address 0x0F code b for digits 0->3.
io(po,load,1)  'pulse load to latch data
delay 50
io(po,load,0)
spi.hex("0B03",2)  'scan limit address 0x03 enable digits 0->3.
io(po,load,1)
delay 50
io(po,load,0)
spi.hex("0A08",2)  'intensity address 0x08 medium intensity.
io(po,load,1)
delay 50
io(po,load,0)
spi.hex("0C01",2)  'power on. 01 for on 00 for off.
io(po,load,1)
delay 50
io(po,load,0)
spi.hex("0F00",2)  'test off. 01 for on 00 for off.
io(po,load,1)
delay 50
io(po,load,0)

'refresh display values once a second
timer 1000, [write7219]
wait

[write7219]
spi.hex(digit1 & n1,2)
io(po,load,1)
delay 50
io(po,load,0)
spi.hex(digit2 & n2,2)
io(po,load,1)
delay 50
io(po,load,0)
spi.hex(digit3 & n3,2)
io(po,load,1)
delay 50
io(po,load,0)
spi.hex(digit4 & n4,2)
io(po,load,1)
delay 50
io(po,load,0)
wait
You do not have the required permissions to view the files attached to this post.
Last edited by joeygbsn on Wed Jul 27, 2016 8:28 am, edited 1 time in total.
User avatar
By Mmiscool
#51542 Thanks for the post. Do you have a small pic or a video that can demonstrate this coolness?