Advertisement
bobbinz

Illuminet

Oct 7th, 2011
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Illuminet
  2. //V3.1
  3.  
  4. #include <SPI.h>
  5. #include <Ethernet.h>
  6.  
  7.  
  8. byte mac[] = {  
  9.   0x09, 0x2, 0xDA, 0x00, 0x14, 0xAF };
  10. byte ip[] = {  
  11.   192,168,62,24 };
  12. byte gateway[] = {  
  13.   192,168,168, 1 };
  14. byte subnet[] = {  
  15.   255, 255, 0, 0 };
  16.  
  17. Server  server(80);                // server port (change this if you are having a local webserver else than the arduino)
  18. int     led1Pin = 8;                // LED pin
  19. int     led2Pin = 7;                // LED pin
  20. int     led = 3;                
  21. int     brightness = 20;    // how bright the LED is
  22. int     fadeAmount = 5;    // how many points to fade the LED by
  23. String  readString = String(30);   // string for fetching data from address
  24. boolean LED1ON = false;             // LED status flag
  25. boolean LED2ON = false;             // Heat status flag  (add more status flags if you need more outputs)
  26.  
  27.  
  28. void setup()
  29. {    
  30.   Serial.begin(4800);
  31.   Ethernet.begin(mac, ip, gateway, subnet);
  32.   pinMode(led1Pin, OUTPUT);
  33.   pinMode(led2Pin, OUTPUT);
  34.   pinMode(led, OUTPUT);
  35. }
  36.  
  37. void loop(){
  38.   Client client = server.available();
  39.   if (client) {
  40.     while (client.connected()) {
  41.       if (client.available()) {
  42.         char c = client.read();
  43.         if (readString.length() < 30) {
  44.           readString.concat(c);
  45.         }
  46.  
  47.         if (c == '\n') {
  48.           int Le = readString.indexOf("L=");
  49.           int He = readString.indexOf("H=");
  50.           if (Le > 1){
  51.             if (readString.substring(Le,(Le+3)) == "L=1") {
  52.               digitalWrite(led1Pin, HIGH);
  53.               Serial.write(17);
  54.               LED1ON = true;
  55.             }
  56.  
  57.             if (readString.substring(Le,(Le+3))== "L=0") {
  58.               digitalWrite(led1Pin, LOW);
  59.               Serial.write(18);
  60.               LED1ON = false;
  61.             }
  62.           }
  63.  
  64.           if (He > 1){
  65.  
  66.             if (readString.substring(He,(He+3)) == "H=1") { //led has to be turned ON
  67.               digitalWrite(led2Pin, HIGH); // set the LED on
  68.               Serial.write(19);
  69.               LED2ON = true;
  70.             }
  71.  
  72.             if (readString.substring(He,(He+3))== "H=0") {
  73.               digitalWrite(led2Pin, LOW);
  74.               Serial.write(20);
  75.               LED2ON = false;
  76.             }
  77.           }
  78.  
  79.           client.println("HTTP/1.1 200 OK");
  80.           client.println("Content-Type: text/html");
  81.           client.println();
  82.           client.print  ("<body style=background-color:whie>");
  83.  
  84.           client.println("<h2 >LED control</h2>");
  85.  
  86.           client.println("<form method=get name=LED> <input type='radio' name='L' value='1'>LED 1 ON<br><input type='radio' name='L' value='0'>LED 1 OFF<br><input type='radio' name='H' value='1'>LED 2 ON<br><input type='radio' name='H' value='0'>LED 2 OFF<br><input type=submit value=Submit></form>");
  87.  
  88.           client.println("<br>");
  89.           client.print("<font size=’5′>LED 1 status: ");
  90.           if (LED1ON == true) {
  91.             client.println("<font size=’5′>ON");
  92.           }
  93.           else {
  94.             client.println("<font size=’5′>OFF");
  95.           }
  96.  
  97.           client.print("<br><font size=’5′>LED 2 status: ");
  98.           if (LED2ON == true) {
  99.             client.println("<font size=’5′>ON");
  100.           }
  101.           else {
  102.             client.println("<font size=’5′>OFF");
  103.           }
  104.  
  105.           client.println("</body></html>");
  106.  
  107.           readString="";
  108.  
  109.           client.stop();
  110.          
  111.           pulse();
  112.  
  113.  
  114.         }
  115.       }
  116.     }
  117.   }
  118.   pulse();
  119. }  
  120.  
  121. void pulse(){
  122.   analogWrite(led, brightness);    
  123.   brightness = brightness + fadeAmount;
  124.   if (brightness == 20 || brightness == 255)
  125.   {
  126.     fadeAmount = -fadeAmount ;
  127.   }  
  128.   delay(30);                  
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement