SHARE
TWEET

Untitled

a guest Apr 24th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<SPI.h>
  2. #include<Ethernet.h>
  3.  
  4. int led = 8;
  5. byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xEF, 0xED};
  6. EthernetServer server(80);
  7. String readString;
  8.  
  9. float temperatur;
  10. void setup() {
  11.   Serial.begin(9600);
  12.   pinMode(led, OUTPUT);
  13.   Ethernet.begin(mac);
  14.   Serial.print("Serverens IP: ");
  15.   Serial.println(Ethernet.localIP());
  16. }
  17. boolean leseTemp;
  18. boolean leseLys;
  19. void loop() {
  20.   EthernetClient client = server.available();
  21.  
  22.   if (client) {
  23.     while (client.connected()) {
  24.       if (client.available()) {
  25.         char c = client.read();
  26.         Serial.print(c);
  27.  
  28.         if (readString.length() < 100) {
  29.           readString += c;
  30.         }
  31.         if (c == '\n') {
  32.           Serial.print(readString);
  33.           client.println("<HTTP/1.1 200 OK>");
  34.           client.println("<Connection-Type: text/html>");
  35.           client.println("<Connection: close>");
  36.           client.println();
  37.  
  38.           client.println("<!DOCTYPE html>");
  39.           client.println("<html>");
  40.           client.println("<head>");
  41.           client.println("<title>Webserver</title>");
  42.           client.println("</head>");
  43.           client.println("<body>");
  44.           client.println("<a href=\"/?button1on\"\"><button>LED ON </button></a>");
  45.           client.println("<a href=\"/?button2off\"\"><button>LED OFF </button></a>");
  46.           client.println("<p>Velg frekvens</p>");
  47.           client.println("<input id=\"faen\"></input><br>");
  48.           client.println("<button id=\"knapp\" onClick=\"function(){window.location.pathname = \"/?frekvens\"+document.getElementById(\"faen\").value;} >Bruk frekvens</button><br>");
  49.           client.println("<a href=\"/?monitoron\"\"><button>Skru på Målinger</button></a>");
  50.           client.println("<a href=\"/?monitoroff\"\"><button>Skru på Målinger</button></a>");
  51.           client.println("<body style=background-color:powderblue>");
  52.  
  53.           String frek = "?frekvens";
  54.  
  55.           delay(1);
  56.           client.stop();
  57.  
  58.           if (readString.indexOf("?button1on") > 0) {
  59.             digitalWrite(led, HIGH);
  60.           }
  61.  
  62.           if (readString.indexOf("?button2off") > 0) {
  63.             digitalWrite(led, LOW);
  64.           }
  65.           if (readString.indexOf(frek) > 0) {
  66.             String frekvens = readString.substring(readString.indexOf(frek)+frek.length());
  67.             int frekvensVerdi = frekvens.toInt();
  68.             //velg pinen som er koblet opp til buzzeren, sett den som writepin i setup
  69.             tone(pin, frekvensVerdi);
  70.             }
  71.           if (readString.indexOf("?monitoron") > 0) {
  72.             //skrur på temp
  73.             leseTemp = true;
  74.             digitalWrite(greenLED, HIGH);
  75.             //lysintensitetmålinger
  76.             leseLys = true;
  77.            
  78.             }
  79.            else if(readString.indexOf("?monitoroff") > 0){
  80.             digitalWrite(greenLED, LOW);
  81.             leseTemp = false;
  82.             leseLys = false;
  83.             }
  84.             if(leseTemp){
  85.             temperatur = analogRead(temppin);
  86.             temperatur = ((temperatur/1024.0) - .5)*100;
  87.             client.println("<p>Temperatur: "+temperatur+"</p>";
  88.             }
  89.           readString = "";
  90.         }
  91.       }
  92.     }
  93.   }
  94.  
  95. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top