Skip to content

Instantly share code, notes, and snippets.

@lingoslinger
Last active December 10, 2015 05:08
Show Gist options
  • Save lingoslinger/4385539 to your computer and use it in GitHub Desktop.
Save lingoslinger/4385539 to your computer and use it in GitHub Desktop.
Modification of https://gist.github.com/4112791 by @cieslak for use with the Parallax 16x2 LCD display with backlight and piezo speaker. Code in the repeat loop is all I needed to change. See orginal gist for more info.
#include "SPI.h"
#include "Ethernet.h"
#include "SoftwareSerial.h"
#include <WebServer.h>
static uint8_t mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // change this to your Ethernet shield's MAC address
static uint8_t ip[] = { 0, 0, 0, 0 }; // change to your network
#define PREFIX ""
WebServer webserver(PREFIX, 80);
SoftwareSerial lcd(2,3); // 2 receives data from ethernet shield, 3 sends characters to the LCD
void showForm(WebServer &server, WebServer::ConnectionType type, char *, bool) {
server.httpSuccess();
if (type != WebServer::HEAD) {
if (type == WebServer::POST) {
P(thxMsg) = "<!doctype HTML><html><body>Thanks!</body></html>";
server.printP(thxMsg);
bool repeat;
char name[16],value[32];
do {
repeat = server.readPOSTparam(name,16,value,32);
if (strcmp(name,"msg") == 0) {
// values for Parallax 16x2 backlit LCD with speaker
// data sheet at www.parallax.com
lcd.write(12); // clear screen
lcd.write(17); // backlight on
lcd.print(value);
lcd.write(212); // play a quarter note...
lcd.write(220); // ... with this tone
delay(3000);
lcd.write(18); // turn backlight off
}
} while (repeat);
}
else {
P(formMsg) = "<!doctype HTML><html><body><form name=\"input\" action=\"/\" method=\"post\"><input type=\"text\" name=\"msg\"><input type=\"submit\" value=\"send\"></form></body></html>";
server.printP(formMsg);
}
}
}
void setup() {
Ethernet.begin(mac, ip);
lcd.begin(9600);
webserver.setDefaultCommand(&showForm);
webserver.begin();
}
void loop() {
char buf[64];
int len = 64;
webserver.processConnection(buf, &len);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment