Last active
December 18, 2015 10:39
-
-
Save feesta/5770518 to your computer and use it in GitHub Desktop.
Hello World for Max72xx and a 4 digit 7-segment display (Electric Imp device code)
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
// Hello World for Max72xx and a 4 digit 7-segment display (Electric Imp device code) | |
hardware.pin7.configure(DIGITAL_OUT); | |
hardware.spi189.configure(SIMPLEX_TX, 10000); | |
function send(data) { | |
hardware.pin7.write(0); // set CS before sending data | |
hardware.spi189.write(data); | |
hardware.pin7.write(1); // release CS after sending data | |
} | |
function configure() { | |
send("\x0C\x00"); // shutdown on | |
//send("\x0F\x01"); // display_test on | |
send("\x0F\x00"); // display_test normal | |
send("\x09\x0F"); // decode mode | |
send("\x0A\x0F"); // intensity | |
send("\x0B\x03"); // scanlimit | |
send("\x0C\x01"); // shutdown normal | |
} | |
configure(); | |
function blankDisplay() { | |
send("\x01\x0F"); | |
send("\x02\x0F"); | |
send("\x03\x0F"); | |
send("\x04\x0F"); | |
} | |
blankDisplay(); | |
function getNumberByte(digit, num) { | |
local digit_blob = blob(2); | |
digit_blob.writen(digit, 'b'); | |
digit_blob.writen(num, 'b'); | |
return digit_blob; | |
} | |
function sendNumber(num) { | |
local digit1 = num % 10; | |
send(getNumberByte(4, digit1)); | |
local digit2 = (num / 10) % 10; | |
send(getNumberByte(3, digit2)); | |
local digit3 = (num / 100) % 10; | |
send(getNumberByte(2, digit3)); | |
local digit4 = (num / 1000) % 10; | |
send(getNumberByte(1, digit4)); | |
//server.log(num); | |
} | |
local vv = 0; | |
function counter() { | |
vv = vv + 1; | |
sendNumber(vv); | |
imp.wakeup(0.03, counter); | |
} | |
counter(); | |
// watchdog keeps the imp from going to sleep | |
function watchdog() { | |
imp.wakeup(5*60, watchdog); | |
server.log("watchdog"); | |
} | |
watchdog(); | |
imp.configure("4 Digit Display", [], []); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment