I've hooked up a Sparkfun serial 16x2 LCD display to an electric imp, and I've been able to display very basic text messages. But I'd like to improve my control of the text: add scrolling right to left, or scrolling up -- fancy effects stolen directly from my local grocery store window display : )
I'm interested in any suggestions or advice for upping my text display capabilities. I've pasted the code I'm currently using, below.
Thanks in advance.
Agent
Device
I'm interested in any suggestions or advice for upping my text display capabilities. I've pasted the code I'm currently using, below.
Thanks in advance.
Agent
// Log the URLs we need
server.log("Turn LED On: " + http.agenturl() + "?led=1");
server.log("Turn LED Off: " + http.agenturl() + "?led=0");
function requestHandler(request, response) {
try {
// check if the user sent led as a query parameter
if ("led" in request.query) {
local ledState = request.query.led.tostring();
// send "led" message to device, and send ledState as the data
device.send("led", ledState); }
// send a response back saying everything was OK.
response.send(200, "OK");
} catch (ex) {
response.send(500, "Internal Server Error: " + ex);
}
}
// register the HTTP handler
http.onrequest(requestHandler);
Device
// create a global variabled called led,
// and assign pin9 to it
led <- hardware.pin9;
lcd <- hardware.uart12;
button <- hardware.pin5;
function buttonPress() {
local state = button.read();
if (state == 1) {
// when the button is released
server.log("release");
} else {
// when the button is pressed
server.log("press");
led.write(0);
lcd.write(254);
lcd.write(0x01);
}
}
button.configure(DIGITAL_IN_PULLUP, buttonPress);
// configure led to be a digital output
led.configure(DIGITAL_OUT);
lcd.configure(9600, 8, PARITY_NONE, 1, NO_RX);
lcd.write(254);
lcd.write(0x01);
lcd.write(124);
lcd.write(155);
// function to turn LED on or off
function setLed(ledState) {
server.log("Set LED: " + ledState);
lcd.write(254);
lcd.write(0x01);
lcd.write(ledState);
led.write(1);
}
// register a handler for "led" messages from the agent
agent.on("led" , function(ledState) {
setLed(ledState);
});