Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- #include <Servo.h>
- Servo myservo; // create servo object to control a servo
- int R; //value to write to red
- int G; //value to write to green
- int B; //value to write to blue
- byte mac[] = {
- 0x90, 0xA2, 0xDA, 0x0D, 0xFE, 0x59
- };
- IPAddress ip(192, 168, 0, 103);
- // Initialize the Ethernet server library
- // with the IP address and port you want to use
- // (port 80 is default for HTTP):
- EthernetServer server(80);
- String readString;
- //////////////////////
- void setup(){
- //start Ethernet
- Ethernet.begin(mac, ip);
- server.begin();
- //enable serial data print
- Serial.begin(9600);
- Serial.println("RGB test"); // so I can keep track of what is loaded
- }
- void loop(){
- // Create a client connection
- EthernetClient client = server.available();
- if (client) {
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- //read char by char HTTP request
- if (readString.length() < 100) {
- //store characters to string
- readString += c;
- //Serial.print(c);
- }
- //if HTTP request has ended
- if (c == '\n') {
- ///////////////
- Serial.print(readString); //see what was captured
- //now output HTML data header
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println();
- client.println("<html>");
- client.println("<body>");
- client.println("<h2>Vpisi vrednosti RGB</h2>");
- client.println("<form>");
- client.println(" R:<br>");
- client.println("<input type='text' name='r'>");
- client.println("<br>");
- client.println("G:<br>");
- client.println("<input type='text' name='g'>");
- client.println("<br>");
- client.println("B:<br>");
- client.println("<input type='text' name='b'>");
- client.println("</form>");
- client.println("</body>");
- client.println("</html>");
- client.println("<INPUT TYPE=SUBMIT NAME='submit' VALUE='Send RGB'>");
- client.println("</FORM>");
- client.println("<BR>");
- delay(1);
- //stopping client
- client.stop();
- /////////////////////
- if (readString.length() >0) {
- int rIdx = readString.indexOf("r");
- int gIdx = readString.indexOf("g");
- int bIdx = readString.indexOf("b");
- int R = readString.substring(rIdx + 2, gIdx - 1).toInt();
- int G = readString.substring(gIdx + 2, bIdx - 1).toInt();
- int B = readString.substring(bIdx + 2).toInt();
- readString=""; //clears variable for new input
- Serial.println(R);
- Serial.println(G);
- Serial.println(B);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement