// Load Wi-Fi library #include // Replace with your network credentials const char* ssid = "REPLACE_WITH_YOUR_SSID"; const char* password = "REPLACE_WITH_YOUR_PASSWORD"; // Set web server port number to 80 WiFiServer server(80); // Variable to store the HTTP request String header; // Auxiliar variables to store the current output state String playAmaj = "off"; String playBmaj = "off"; String playCmaj = "off"; String playDmaj = "off"; String playEmaj = "off"; String playFmaj = "off"; String playGmaj = "off"; String playAmin = "off"; String playBmin = "off"; String playCmin = "off"; String playDmin = "off"; String playEmin = "off"; String playFmin = "off"; String playGmin = "off"; String playCD = "off"; // Assign output variables to GPIO pins const int output1 = 25; const int output2 = 26; const int output3 = 27; const int output4 = 14; const int output5 = 12; const int output6 = 16; const int output7 = 17; const int output8 = 18; const int output9 = 19; int count = 0; int songcount = 0; // Current time unsigned long currentTime = millis(); // Previous time unsigned long previousTime = 0; // Define timeout time in milliseconds (example: 2000ms = 2s) const long timeoutTime = 2000; void setup() { Serial.begin(115200); // Initialize the output variables as outputs pinMode(output1, INPUT); pinMode(output2, INPUT); pinMode(output3, INPUT); pinMode(output4, INPUT); pinMode(output5, INPUT); pinMode(output6, INPUT); pinMode(output7, INPUT); pinMode(output8, INPUT); pinMode(output9, INPUT); // Connect to Wi-Fi network with SSID and password Serial.print("Connecting to "); Serial.println(ssid); //WiFi.begin("MIT"); WiFi.begin("FiOS-02O5H", "pods7582try7142why"); //WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } // Print local IP address and start web server Serial.println(""); Serial.println("WiFi connected."); Serial.println("IP address: "); Serial.println(WiFi.localIP()); server.begin(); } void loop(){ WiFiClient client = server.available(); // Listen for incoming clients if (client) { // If a new client connects, currentTime = millis(); previousTime = currentTime; Serial.println("New Client."); // print a message out in the serial port String currentLine = ""; // make a String to hold incoming data from the client while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected currentTime = millis(); if (client.available()) { // if there's bytes to read from the client, char c = client.read(); // read a byte, then Serial.write(c); // print it out the serial monitor header += c; if (c == '\n') { // if the byte is a newline character // if the current line is blank, you got two newline characters in a row. // that's the end of the client HTTP request, so send a response: if (currentLine.length() == 0) { // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) // and a content-type so the client knows what's coming, then a blank line: client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println("Connection: close"); client.println(); // turns the GPIOs on and off if (header.indexOf("GET /Gmaj/on") >= 0) { Serial.println("Play Gmaj"); playGmaj = "on"; while (count < 1000){ playGmaj = "on"; pinMode(output1, OUTPUT); pinMode(output3, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output3, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output3, INPUT); pinMode(output3, OUTPUT); pinMode(output2, OUTPUT); digitalWrite(output3, LOW); digitalWrite(output2, HIGH); delay(1); pinMode(output3, INPUT); pinMode(output2, INPUT); pinMode(output8, OUTPUT); pinMode(output2, OUTPUT); digitalWrite(output8, LOW); digitalWrite(output2, HIGH); delay(1); pinMode(output8, INPUT); pinMode(output2, INPUT); count = count + 1; } count = 0; } else if (header.indexOf("GET /Gmaj/off") >= 0) { Serial.println("Gmaj done"); playGmaj = "off"; count = 0; // pinMode(output1, INPUT); //pinMode(output2, INPUT); } else if (header.indexOf("GET /Amaj/on") >= 0) { Serial.println("Play Amaj"); playAmaj = "on"; while (count < 1000){ playAmaj = "on"; pinMode(output1, OUTPUT); pinMode(output4, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output4, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output4, INPUT); pinMode(output1, OUTPUT); pinMode(output5, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output5, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output5, INPUT); pinMode(output1, OUTPUT); pinMode(output6, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output6, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output6, INPUT); count = count + 1; } count = 0; } else if (header.indexOf("GET /Amaj/off") >= 0) { Serial.println("Amaj done"); playAmaj = "off"; count = 0; } else if (header.indexOf("GET /Bmaj/on") >= 0) { Serial.println("Play Bmaj"); playBmaj = "on"; while (count < 800){ playBmaj = "on"; pinMode(output1, OUTPUT); pinMode(output7, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output7, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output7, INPUT); pinMode(output2, OUTPUT); pinMode(output5, OUTPUT); digitalWrite(output2, LOW); digitalWrite(output5, HIGH); delay(1); pinMode(output2, INPUT); pinMode(output5, INPUT); pinMode(output2, OUTPUT); pinMode(output6, OUTPUT); digitalWrite(output2, LOW); digitalWrite(output6, HIGH); delay(1); pinMode(output2, INPUT); pinMode(output6, INPUT); pinMode(output2, OUTPUT); pinMode(output7, OUTPUT); digitalWrite(output2, LOW); digitalWrite(output7, HIGH); delay(1); pinMode(output2, INPUT); pinMode(output7, INPUT); count = count + 1; } count = 0; } else if (header.indexOf("GET /Bmaj/off") >= 0) { Serial.println("Bmaj done"); playBmaj = "off"; count = 0; } else if (header.indexOf("GET /Cmaj/on") >= 0) { Serial.println("Play Cmaj"); playCmaj = "on"; while (count < 1000){ playCmaj = "on"; pinMode(output6, OUTPUT); pinMode(output1, OUTPUT); digitalWrite(output6, LOW); digitalWrite(output1, HIGH); delay(1); pinMode(output6, INPUT); pinMode(output1, INPUT); pinMode(output1, OUTPUT); pinMode(output4, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output4, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output4, INPUT); pinMode(output4, OUTPUT); pinMode(output2, OUTPUT); digitalWrite(output4, LOW); digitalWrite(output2, HIGH); delay(1); pinMode(output4, INPUT); pinMode(output2, INPUT); count = count + 1; } count = 0; } else if (header.indexOf("GET /Cmaj/off") >= 0) { Serial.println("Cmaj done"); playCmaj = "off"; count = 0; } else if (header.indexOf("GET /Dmaj/on") >= 0) { Serial.println("Play Dmaj"); playDmaj = "on"; while (count < 1000){ playDmaj = "on"; pinMode(output1, OUTPUT); pinMode(output7, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output7, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output7, INPUT); pinMode(output1, OUTPUT); pinMode(output5, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output5, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output5, INPUT); pinMode(output7, OUTPUT); pinMode(output2, OUTPUT); digitalWrite(output7, LOW); digitalWrite(output2, HIGH); delay(1); pinMode(output7, INPUT); pinMode(output2, INPUT); count = count + 1; } count = 0; } else if (header.indexOf("GET /Dmaj/off") >= 0) { Serial.println("Dmaj done"); playDmaj = "off"; count = 0; } else if (header.indexOf("GET /Emaj/on") >= 0) { Serial.println("Play Emaj"); playEmaj = "on"; while (count < 1000){ playEmaj = "on"; pinMode(output5, OUTPUT); pinMode(output1, OUTPUT); digitalWrite(output5, LOW); digitalWrite(output1, HIGH); delay(1); pinMode(output5, INPUT); pinMode(output1, INPUT); pinMode(output1, OUTPUT); pinMode(output3, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output3, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output3, INPUT); pinMode(output1, OUTPUT); pinMode(output4, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output4, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output4, INPUT); count = count + 1; } count = 0; } else if (header.indexOf("GET /Emaj/off") >= 0) { Serial.println("Emaj done"); playEmaj = "off"; count = 0; } else if (header.indexOf("GET /Fmaj/on") >= 0) { Serial.println("Play Fmaj"); playFmaj = "on"; while (count < 800){ playFmaj = "on"; pinMode(output6, OUTPUT); pinMode(output1, OUTPUT); digitalWrite(output6, LOW); digitalWrite(output1, HIGH); delay(1); pinMode(output6, INPUT); pinMode(output1, INPUT); pinMode(output7, OUTPUT); pinMode(output1, OUTPUT); digitalWrite(output7, LOW); digitalWrite(output1, HIGH); delay(1); pinMode(output7, INPUT); pinMode(output1, INPUT); pinMode(output1, OUTPUT); pinMode(output5, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output5, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output5, INPUT); pinMode(output5, OUTPUT); pinMode(output2, OUTPUT); digitalWrite(output5, LOW); digitalWrite(output2, HIGH); delay(1); pinMode(output5, INPUT); pinMode(output2, INPUT); count = count + 1; } count = 0; } else if (header.indexOf("GET /Fmaj/off") >= 0) { Serial.println("Fmaj done"); playFmaj = "off"; count = 0; } else if (header.indexOf("GET /Amin/on") >= 0) { Serial.println("Play Amin"); playAmin = "on"; while (count < 1000){ playAmin = "on"; pinMode(output6, OUTPUT); pinMode(output1, OUTPUT); digitalWrite(output6, LOW); digitalWrite(output1, HIGH); delay(1); pinMode(output6, INPUT); pinMode(output1, INPUT); pinMode(output1, OUTPUT); pinMode(output4, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output4, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output4, INPUT); pinMode(output1, OUTPUT); pinMode(output5, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output5, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output5, INPUT); count = count + 1; } count = 0; } else if (header.indexOf("GET /Amin/off") >= 0) { Serial.println("Amin done"); playAmin = "off"; count = 0; } else if (header.indexOf("GET /Bmin/on") >= 0) { Serial.println("Play Bmin"); playBmin = "on"; while (count < 600){ playBmin = "on"; pinMode(output1, OUTPUT); pinMode(output3, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output3, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output3, INPUT); pinMode(output1, OUTPUT); pinMode(output7, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output7, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output7, INPUT); pinMode(output7, OUTPUT); pinMode(output2, OUTPUT); digitalWrite(output7, LOW); digitalWrite(output2, HIGH); delay(1); pinMode(output7, INPUT); pinMode(output2, INPUT); pinMode(output2, OUTPUT); pinMode(output5, OUTPUT); digitalWrite(output2, LOW); digitalWrite(output5, HIGH); delay(1); pinMode(output2, INPUT); pinMode(output5, INPUT); pinMode(output2, OUTPUT); pinMode(output6, OUTPUT); digitalWrite(output2, LOW); digitalWrite(output6, HIGH); delay(1); pinMode(output2, INPUT); pinMode(output6, INPUT); count = count + 1; } count = 0; } else if (header.indexOf("GET /Bmin/off") >= 0) { Serial.println("Bmin done"); playBmin = "off"; count = 0; } else if (header.indexOf("GET /Cmin/on") >= 0) { Serial.println("Play Cmin"); playCmin = "on"; while (count < 600){ playCmin = "on"; pinMode(output8, OUTPUT); pinMode(output2, OUTPUT); digitalWrite(output8, LOW); digitalWrite(output2, HIGH); delay(1); pinMode(output8, INPUT); pinMode(output2, INPUT); pinMode(output4, OUTPUT); pinMode(output2, OUTPUT); digitalWrite(output4, LOW); digitalWrite(output2, HIGH); delay(1); pinMode(output4, INPUT); pinMode(output2, INPUT); pinMode(output2, OUTPUT); pinMode(output7, OUTPUT); digitalWrite(output2, LOW); digitalWrite(output7, HIGH); delay(1); pinMode(output2, INPUT); pinMode(output7, INPUT); pinMode(output6, OUTPUT); pinMode(output3, OUTPUT); digitalWrite(output6, LOW); digitalWrite(output3, HIGH); delay(1); pinMode(output6, INPUT); pinMode(output3, INPUT); pinMode(output7, OUTPUT); pinMode(output3, OUTPUT); digitalWrite(output7, LOW); digitalWrite(output3, HIGH); delay(1); pinMode(output7, INPUT); pinMode(output3, INPUT); count = count + 1; } count = 0; } else if (header.indexOf("GET /Cmin/off") >= 0) { Serial.println("Cmin done"); playCmin = "off"; count = 0; } else if (header.indexOf("GET /Dmin/on") >= 0) { Serial.println("Play Dmin"); playDmin = "on"; while (count < 1000){ playDmin = "on"; pinMode(output1, OUTPUT); pinMode(output5, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output5, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output5, INPUT); pinMode(output1, OUTPUT); pinMode(output7, OUTPUT); digitalWrite(output7, LOW); digitalWrite(output1, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output7, INPUT); pinMode(output7, OUTPUT); pinMode(output2, OUTPUT); digitalWrite(output7, LOW); digitalWrite(output2, HIGH); delay(1); pinMode(output7, INPUT); pinMode(output2, INPUT); count = count + 1; } count = 0; } else if (header.indexOf("GET /Dmin/off") >= 0) { Serial.println("Dmin done"); playDmin = "off"; count = 0; } else if (header.indexOf("GET /Emin/on") >= 0) { Serial.println("Play Emin"); playEmin = "on"; while (count < 1000){ playEmin = "on"; pinMode(output1, OUTPUT); pinMode(output3, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output3, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output3, INPUT); pinMode(output1, OUTPUT); pinMode(output4, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output4, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output4, INPUT); count = count + 1; } count = 0; } else if (header.indexOf("GET /Emin/off") >= 0) { Serial.println("Emin done"); playEmin = "off"; count = 0; } else if (header.indexOf("GET /Fmin/on") >= 0) { Serial.println("Play Fmin"); playFmin = "on"; while (count < 790){ playFmin = "on"; pinMode(output2, OUTPUT); pinMode(output1, OUTPUT); digitalWrite(output2, LOW); digitalWrite(output1, HIGH); delay(1); pinMode(output2, INPUT); pinMode(output1, INPUT); pinMode(output7, OUTPUT); pinMode(output1, OUTPUT); digitalWrite(output7, LOW); digitalWrite(output1, HIGH); delay(1); pinMode(output7, INPUT); pinMode(output1, INPUT); pinMode(output4, OUTPUT); pinMode(output2, OUTPUT); digitalWrite(output4, LOW); digitalWrite(output2, HIGH); delay(1); pinMode(output4, INPUT); pinMode(output2, INPUT); pinMode(output2, OUTPUT); pinMode(output5, OUTPUT); digitalWrite(output5, LOW); digitalWrite(output2, HIGH); delay(1); pinMode(output2, INPUT); pinMode(output5, INPUT); count = count + 1; } count = 0; } else if (header.indexOf("GET /Fmin/off") >= 0) { Serial.println("Fmin done"); playFmin = "off"; count = 0; } else if (header.indexOf("GET /Gmin/on") >= 0) { Serial.println("Play Gmin"); playGmin = "on"; while (count < 800){ playGmin = "on"; pinMode(output3, OUTPUT); pinMode(output2, OUTPUT); digitalWrite(output3, LOW); digitalWrite(output2, HIGH); delay(1); pinMode(output3, INPUT); pinMode(output2, INPUT); pinMode(output8, OUTPUT); pinMode(output2, OUTPUT); digitalWrite(output8, LOW); digitalWrite(output2, HIGH); delay(1); pinMode(output8, INPUT); pinMode(output2, INPUT); pinMode(output5, OUTPUT); pinMode(output3, OUTPUT); digitalWrite(output5, LOW); digitalWrite(output3, HIGH); delay(1); pinMode(output5, INPUT); pinMode(output3, INPUT); pinMode(output6, OUTPUT); pinMode(output3, OUTPUT); digitalWrite(output6, LOW); digitalWrite(output3, HIGH); delay(1); pinMode(output6, INPUT); pinMode(output3, INPUT); count = count + 1; } count = 0; } else if (header.indexOf("GET /Gmin/off") >= 0) { Serial.println("Gmin done"); playGmin = "off"; count = 0; } else if (header.indexOf("GET /CD/on") >= 0){ Serial.println("CD Playing"); playCD = "on"; while (songcount <= 2){ while (count <= 800){ //D pinMode(output1, OUTPUT); pinMode(output7, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output7, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output7, INPUT); pinMode(output1, OUTPUT); pinMode(output5, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output5, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output5, INPUT); pinMode(output7, OUTPUT); pinMode(output2, OUTPUT); digitalWrite(output7, LOW); digitalWrite(output2, HIGH); delay(1); pinMode(output7, INPUT); pinMode(output2, INPUT); count = count + 1; } count = 0; while (count <= 800){ //Dmaj7 pinMode(output1, OUTPUT); pinMode(output7, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output7, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output7, INPUT); pinMode(output1, OUTPUT); pinMode(output5, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output5, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output5, INPUT); pinMode(output1, OUTPUT); pinMode(output6, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output6, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output6, INPUT); count = count + 1; } count = 0; while (count <= 790){ //Em pinMode(output1, OUTPUT); pinMode(output3, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output3, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output3, INPUT); pinMode(output1, OUTPUT); pinMode(output4, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output4, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output4, INPUT); count = count + 1; } count = 0; while (count <= 400){ //G pinMode(output1, OUTPUT); pinMode(output3, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output3, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output3, INPUT); pinMode(output3, OUTPUT); pinMode(output2, OUTPUT); digitalWrite(output3, LOW); digitalWrite(output2, HIGH); delay(1); pinMode(output3, INPUT); pinMode(output2, INPUT); pinMode(output8, OUTPUT); pinMode(output2, OUTPUT); digitalWrite(output8, LOW); digitalWrite(output2, HIGH); delay(1); pinMode(output8, INPUT); pinMode(output2, INPUT); count = count + 1; } count = 0; while (count <= 400){ //A pinMode(output1, OUTPUT); pinMode(output4, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output4, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output4, INPUT); pinMode(output1, OUTPUT); pinMode(output5, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output5, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output5, INPUT); pinMode(output1, OUTPUT); pinMode(output6, OUTPUT); digitalWrite(output1, LOW); digitalWrite(output6, HIGH); delay(1); pinMode(output1, INPUT); pinMode(output6, INPUT); count = count + 1; } count = 0; songcount = songcount + 1; } songcount = 0; } else if (header.indexOf("GET /CD/off") >= 0) { Serial.println("CD done"); playCD = "off"; count = 0; songcount = 0; } // Display the HTML web page client.println(""); client.println(""); client.println(""); // CSS to style the on/off buttons // Feel free to change the background-color and font-size attributes to fit your preferences client.println(""); //client.println(".button3 {background-color: #555555;}"); // Web Page Heading client.println("

Emma's LED Guitar!

"); client.println("

Major Chords

"); client.println("

A Major

"); client.println("

"); client.println("

B Major

"); client.println("

"); client.println("

C Major

"); client.println("

"); client.println("

D Major

"); client.println("

"); client.println("

E Major

"); client.println("

"); client.println("

F Major

"); client.println("

"); client.println("

G Major

"); client.println("

"); client.println("

Minor Chords

"); client.println("

A Minor

"); client.println("

"); client.println("

B Minor

"); client.println("

"); client.println("

C Minor

"); client.println("

"); client.println("

D Minor

"); client.println("

"); client.println("

E Minor

"); client.println("

"); client.println("

F Minor

"); client.println("

"); client.println("

G Minor

"); client.println("

"); client.println("

Songs

"); client.println("

Cigarette Daydreams

"); client.println("

"); client.println(""); // The HTTP response ends with another blank line client.println(); // Break out of the while loop break; } else { // if you got a newline, then clear currentLine currentLine = ""; } } else if (c != '\r') { // if you got anything else but a carriage return character, currentLine += c; // add it to the end of the currentLine } } } // Clear the header variable header = ""; // Close the connection client.stop(); Serial.println("Client disconnected."); Serial.println(""); } }