//Created for the MasonJar Dice Roller project #include #include Servo servo; const char* ssid = "XXXXXXXXXXXXX"; const char* password = "XXXXXXXXXXX"; WiFiServer server(80); void setup() { Serial.begin(115200); delay(10); servo.attach(2);//pin D4 Serial.println(); Serial.println(); Serial.print("Connecting to WiFi router..."); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); // Start the server server.begin(); Serial.println("Server started"); // Print the IP address on serial monitor Serial.print("Use this URL to connect: "); Serial.print(WiFi.localIP()); Serial.println("/"); } void loop() { // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; } Serial.println("new client"); while(!client.available()){ delay(1); } String request = client.readStringUntil('\r'); Serial.println(request); client.flush(); int value = 0; if (request.indexOf("/Req=0") != -1) { servo.write(0); //spin roller delay(1000); servo.write(90); //stop value=0; } if (request.indexOf("/Req=90") != -1) { servo.write(110); delay(1000); servo.write(90); value=90; } if (request.indexOf("/Req=120") != -1) { servo.write(120); delay(1000); servo.write(90); value=120; } if (request.indexOf("/Req=180") != -1) { servo.write(0); delay(1500); servo.write(90); value=180; } client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(""); // do not forget this one client.println(""); client.println(""); client.println(""); client.println("

Dice Roller

"); client.println(""); client.println(""); client.println("

"); client.println("

"); client.println("

"); client.println("

"); client.println(""); client.println(""); delay(1); Serial.println("Client disonnected"); Serial.println(""); }