Created
April 14, 2015 02:23
-
-
Save pearlchen/f70d201fcffe31495a4b to your computer and use it in GitHub Desktop.
Make a little * dance across your Grove LCD screen using JavaScript on the Intel Edison or Intel Galileo. Video: https://twitter.com/PearlChen/status/587808490405625856
This file contains hidden or 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
var mraa = require ('mraa'); | |
/* | |
If you get any mraa missing errors, run this on your board: | |
$ echo "src mraa-upm http://iotdk.intel.com/repos/1.1/intelgalactic" > /etc/opkg/mraa-upm.conf | |
$ opkg update | |
$ opkg install libmraa0 | |
*/ | |
var LCD = require ('jsupm_i2clcd'); | |
/* | |
If you get any upm missing errors, run this on your board: | |
$ opkg install upm | |
*/ | |
// Initialize the LCD. The 1st param is the BUS ID. | |
// Intel Edison: Use 6 | |
// Intel Galileo Gen 2: Use 6 (unconfirmed) | |
// Intel Galileo Gen 1: Use 0 | |
var myLCD = new LCD.Jhd1313m1(6, 0x3E, 0x62); | |
var LCD_MESSAGE = "*"; | |
var LCD_COLUMNS = 16; | |
var LCD_ROWS = 2; | |
var row = 0; | |
var column = 0; | |
updateLcd(); | |
function updateLcd(){ | |
// write message to LCD at cursor position | |
// plus update column variable while we're at it | |
myLCD.setCursor(row, column++); | |
myLCD.write(LCD_MESSAGE); | |
// figure out if * is at end of row, and reset if needed | |
if (column == LCD_COLUMNS) { | |
column = 0; | |
row = ( row == 1 ? 0 : 1); | |
} | |
//note: anything below a 100-200ms refresh rate is a bit too blurry | |
setTimeout(clearLcd, 200); | |
} | |
function clearLcd(){ | |
// wipe out any chars on the LCD screen | |
myLCD.clear(); | |
// if you try to clear the LCD and update immediately, you get nuthin' | |
// so use a setTimeout as a delay | |
setTimeout(updateLcd, 30); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment