Created
October 7, 2011 08:31
-
-
Save lrvick/1269776 to your computer and use it in GitHub Desktop.
Simple Arduino Webserver With Hits/IP on LCD & DHCP
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
#include <Wire.h> | |
#include <LiquidCrystal.h> | |
#include <SPI.h> | |
#include <Ethernet.h> | |
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE }; | |
EthernetServer server(80); | |
LiquidCrystal lcd(0); | |
int hits = 0; | |
void setup(){ | |
lcd.begin(16, 2); | |
lcd.print("PonyDuino!"); | |
lcd.setCursor(0, 1); | |
lcd.print("hits:"); | |
Ethernet.begin(mac); | |
lcd.setCursor(0,0); | |
lcd.print(Ethernet.localIP()); | |
server.begin(); | |
} | |
void loop(){ | |
EthernetClient client = server.available(); | |
if (client) { | |
while (client.connected()) { | |
if (client.available()) { | |
client.println("HTTP/1.1 200 OK"); | |
client.println("Content-Type: text/html"); | |
client.println(); | |
client.print("<h1>Hai. I am Lance's Arduino! <3</h1>"); | |
client.print("<h2>I can has analog portz:</h2>"); | |
for (int analogChannel = 0; analogChannel < 6; analogChannel++) { | |
client.print("analog input "); | |
client.print(analogChannel); | |
client.print(" is "); | |
client.print(analogRead(analogChannel)); | |
client.println("<br />"); | |
} | |
client.print("<h2>And here is a pretty pony!</h2>"); | |
client.print("<img src='http://powet.tv/powetblog/wp-content/uploads/2011/02/my_little_pony_friendship_is_magic_rarity.jpeg' />"); | |
hits = ++hits; | |
lcd.setCursor(6,5); | |
lcd.print(hits); | |
break; | |
} | |
} | |
client.stop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment