Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Illuminet
- //V3.1
- #include <SPI.h>
- #include <Ethernet.h>
- byte mac[] = {
- 0x09, 0x2, 0xDA, 0x00, 0x14, 0xAF };
- byte ip[] = {
- 192,168,62,24 };
- byte gateway[] = {
- 192,168,168, 1 };
- byte subnet[] = {
- 255, 255, 0, 0 };
- Server server(80); // server port (change this if you are having a local webserver else than the arduino)
- int led1Pin = 8; // LED pin
- int led2Pin = 7; // LED pin
- int led = 3;
- int brightness = 20; // how bright the LED is
- int fadeAmount = 5; // how many points to fade the LED by
- String readString = String(30); // string for fetching data from address
- boolean LED1ON = false; // LED status flag
- boolean LED2ON = false; // Heat status flag (add more status flags if you need more outputs)
- void setup()
- {
- Serial.begin(4800);
- Ethernet.begin(mac, ip, gateway, subnet);
- pinMode(led1Pin, OUTPUT);
- pinMode(led2Pin, OUTPUT);
- pinMode(led, OUTPUT);
- }
- void loop(){
- Client client = server.available();
- if (client) {
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- if (readString.length() < 30) {
- readString.concat(c);
- }
- if (c == '\n') {
- int Le = readString.indexOf("L=");
- int He = readString.indexOf("H=");
- if (Le > 1){
- if (readString.substring(Le,(Le+3)) == "L=1") {
- digitalWrite(led1Pin, HIGH);
- Serial.write(17);
- LED1ON = true;
- }
- if (readString.substring(Le,(Le+3))== "L=0") {
- digitalWrite(led1Pin, LOW);
- Serial.write(18);
- LED1ON = false;
- }
- }
- if (He > 1){
- if (readString.substring(He,(He+3)) == "H=1") { //led has to be turned ON
- digitalWrite(led2Pin, HIGH); // set the LED on
- Serial.write(19);
- LED2ON = true;
- }
- if (readString.substring(He,(He+3))== "H=0") {
- digitalWrite(led2Pin, LOW);
- Serial.write(20);
- LED2ON = false;
- }
- }
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println();
- client.print ("<body style=background-color:whie>");
- client.println("<h2 >LED control</h2>");
- 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>");
- client.println("<br>");
- client.print("<font size=’5′>LED 1 status: ");
- if (LED1ON == true) {
- client.println("<font size=’5′>ON");
- }
- else {
- client.println("<font size=’5′>OFF");
- }
- client.print("<br><font size=’5′>LED 2 status: ");
- if (LED2ON == true) {
- client.println("<font size=’5′>ON");
- }
- else {
- client.println("<font size=’5′>OFF");
- }
- client.println("</body></html>");
- readString="";
- client.stop();
- pulse();
- }
- }
- }
- }
- pulse();
- }
- void pulse(){
- analogWrite(led, brightness);
- brightness = brightness + fadeAmount;
- if (brightness == 20 || brightness == 255)
- {
- fadeAmount = -fadeAmount ;
- }
- delay(30);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement