Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <NativeEthernet.h>
- /**Function defs**/
- void svgHeader();
- void svgFooter();
- void polyLineBegin();
- void polyLineEnd();
- void startClient();
- void endClient();
- byte mac[] = {
- 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
- };
- //IPAddress ip(192, 168, 0, 177);
- IPAddress ip(10, 1, 0, 177);
- EthernetServer server(80);
- void setup() {
- delay(5000); //you want this here belive me. reason: tl;dr
- // Open serial communications and wait for port to open:
- Serial.begin(9600);
- while (!Serial) {
- ; // wait for serial port to connect. Needed for native USB port only
- }
- Serial.println("Ethernet WebServer Example");
- // start the Ethernet connection and the server:
- Ethernet.begin(mac, ip);
- // Check for Ethernet hardware present
- if (Ethernet.hardwareStatus() == EthernetNoHardware) {
- Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
- while (true) {
- delay(1); // do nothing, no point running without Ethernet hardware
- }
- }
- if (Ethernet.linkStatus() == LinkOFF) {
- Serial.println("Ethernet cable is not connected.");
- }
- // start the server
- server.begin();
- Serial.print("server is at ");
- Serial.println(Ethernet.localIP());
- }
- /*Global Vars*
- * located here as to wait for defintion of client as related to server in
- * setup function
- */
- EthernetClient client = server.available();
- int potX = A8;
- int potY = A9;
- int sensorValX = 0;
- int sensorValY = 0;
- int oldX = 0;
- int oldY = 0;
- void loop() {
- // listen for incoming clients
- // EthernetClient client = server.available();
- if (client) {
- // an http request ends with a blank line
- boolean currentLineIsBlank = true;
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- Serial.write(c);
- // if you've gotten to the end of the line (received a newline
- // character) and the line is blank, the http request has ended,
- // so you can send a reply
- if (c == '\n' && currentLineIsBlank) {
- startClient();
- // output the value of each analog input pin
- sensorValX = analogRead(potX);
- sensorValY = analogRead(potY);
- /*dont draw if pots not changing
- Ah but the sensors are noisy, so thresholding
- */
- int threshold =3;
- int xVariance = abs(sensorValX-oldX);
- int yVariance = abs(sensorValY-oldY);
- if (((xVariance >=threshold) && (yVariance >= threshold)) ||xVariance >=threshold || yVariance >=threshold){
- oldX=sensorValX;
- oldY=sensorValY;
- client.print(sensorValX);
- client.print(",");
- client.print(sensorValY);
- client.print(",");
- delay(100);
- }else{
- ; //dont do shi.
- }
- endClient();
- }
- // client.println("<a href=\"/?button1on\">Save Drawing</a>");
- break;
- }
- }
- }
- // give the web browser time to receive the data
- delay(1);
- // close the connection:
- client.stop();
- Serial.println("client disconnected");
- } // end loop
- /**Functions**/
- void startClient(){
- // send a standard http response header
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println("Connection: close"); // the connection will be closed after completion of the response
- client.println("Refresh: 5"); // refresh the page automatically every 5 sec
- client.println();
- client.println("<!DOCTYPE HTML>");
- client.println("<html>");
- client.println("<body>");
- }
- void endClient(){
- client.println("</body>");
- client.println("</html>");
- }
- void polyLineBegin(){
- //Serial.println ("<polyline points=\""); //x,y points go here
- client.println ("<polyline points=\"");
- }
- void polyLineEnd(){
- // Serial.println ("0, 0\" stroke=\"red\" fill=\"transparent\" stroke-width=\"5\"/>"); //a dirty hack to avoid dealing with 1 last trailing comma.
- client.println ("0, 0\" stroke=\"red\" fill=\"transparent\" stroke-width=\"5\"/>");
- }
- void svgHeader(){
- //Serial.println("<svg width=\"1023\" height=\"1023\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">");
- client.println("<svg width=\"1023\" height=\"1023\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">");
- };
- void svgFooter(){
- //Serial.println ("</svg>");
- client.println("</svg>");
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement