Last active
November 14, 2018 20:33
-
-
Save mjarkk/2e688160b2254bfff47fd326148950b4 to your computer and use it in GitHub Desktop.
This file contains 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 <SPI.h> | |
#include <Ethernet.h> | |
#define REDPIN 5 | |
#define GREENPIN 3 | |
#define BLUEPIN 6 | |
#define WHITEPIN 10 | |
byte mac[] = { | |
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED | |
}; | |
IPAddress ip(192, 168, 2, 177); | |
EthernetServer server(80); | |
void setup() { | |
pinMode(REDPIN, OUTPUT); | |
pinMode(GREENPIN, OUTPUT); | |
pinMode(BLUEPIN, OUTPUT); | |
pinMode(WHITEPIN, OUTPUT); | |
if (Ethernet.hardwareStatus() == EthernetNoHardware) { | |
// show red color becaue of no internet adapter | |
analogWrite(REDPIN, 255); | |
while (true) { | |
delay(1); | |
} | |
} | |
if (Ethernet.linkStatus() == LinkOFF) { | |
analogWrite(GREENPIN, 255); | |
} | |
server.begin(); | |
} | |
void loop() { | |
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(); | |
if (c == '\n' && currentLineIsBlank) { | |
client.println("HTTP/1.1 200 OK"); | |
client.println("Content-Type: text/html"); | |
client.println("Connection: close"); | |
client.println(); | |
client.println("ok"); | |
break; | |
} | |
if (c == '\n') { | |
currentLineIsBlank = true; | |
} else if (c != '\r') { | |
currentLineIsBlank = false; | |
} | |
} | |
} | |
delay(1); | |
client.stop(); | |
} | |
// int r, g, b, w; | |
// | |
// w = 255; | |
// analogWrite(WHITEPIN, w); | |
// fade from blue to violet | |
// for (r = 0; r < 256; r++) { | |
// analogWrite(REDPIN, r); | |
// delay(FADESPEED); | |
// } | |
// fade from violet to red | |
// for (b = 255; b > 0; b--) { | |
// analogWrite(BLUEPIN, b); | |
// delay(FADESPEED); | |
// } | |
// fade from red to yellow | |
// for (g = 0; g < 256; g++) { | |
// analogWrite(GREENPIN, g); | |
// delay(FADESPEED); | |
// } | |
// fade from yellow to green | |
// for (r = 255; r > 0; r--) { | |
// analogWrite(REDPIN, r); | |
// delay(FADESPEED); | |
// } | |
// fade from green to teal | |
// for (b = 0; b < 256; b++) { | |
// analogWrite(BLUEPIN, b); | |
// delay(FADESPEED); | |
// } | |
// fade from teal to blue | |
// for (g = 255; g > 0; g--) { | |
// analogWrite(GREENPIN, g); | |
// delay(FADESPEED); | |
// } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment