Hello forum,
still learning how to use the imp, I’ve put together following code to control a Sparkfun serial LCD on Pin1 and an ordinary LED on Pin7:
`
hardware.uart12.configure(4800, 8, PARITY_NONE, 1, NO_RX);
CharactersInLCD <- 16;
Message <- “abcdefghijklm123nopqrstuvwxyz456”;
// Variable to represent LED state
LEDstate <- 0;
function LCDClear()
{
hardware.uart12.write(254);
hardware.uart12.write(0x01);
hardware.uart12.write(254);
hardware.uart12.write(128);
//LCDBoxCursorOff();
}
function LCDWriteMessage(LCDMessage)
{
hardware.uart12.write(LCDMessage);
}
//Main Execution loop
function loop()
{
//Loop Activities - executed once every Wakeup
imp.wakeup(0.5, loop);
LEDstate = LEDstate?0:1;
hardware.pin7.write(LEDstate);
// LCDClear();
//LCDWriteMessage(Message);
}
class inputHTTP extends InputPort {
//name = “response”;
type = “string”;
function set(httpVal) {
server.log("Received val "+httpVal.x);
LCDClear();
LCDWriteMessage(format(httpVal.x));
}
}
hardware.pin7.configure(DIGITAL_OUT);
//Setup Activities - only executed once
imp.configure(“LCD Examples”, [inputHTTP()], []);
//SerLCDTypeSetup(6);
LCDClear();
//LCDWriteMessage(Message);
//Pause 2 Seconds before starting the main loop - adjust to taste
imp.wakeup(0.5, loop);`
In the planner, I’ve added a http in node and connected it to the impee. While the program is running on the imp, the LED is toggling. If I send a http POST request to the imp, it gets displayed on the sparkfun LCD. But, it doesn’t allways work. Sometimes the LED hangs in it’s current state (on or off) for a few seconds and nothing else happens. Sometimes it keeps blinking, but nothing is displayed on the LCD.
On my webserver, I use following code, derived from the examples:
`
Regards,
Leo