Skip to content
Snippets Groups Projects
Commit d597eaa9 authored by Mel Avina-Beltran's avatar Mel Avina-Beltran
Browse files

Upload Arduino code for Web Server

parent c3ed0ad8
Branches
No related merge requests found
No preview for this file type
...@@ -38,3 +38,23 @@ void servosWakeUp() { ...@@ -38,3 +38,23 @@ void servosWakeUp() {
servo_left.write(0); servo_left.write(0);
servo_right.write(180); servo_right.write(180);
} }
#include <Servo.h>
static const int SERVO-LEFT = D1;
static const int SERVO-RIGHT = D2;
Servo servo_left;
Servo servo_right;
void setup() {
Serial.begin(115200);
servo_left.attach(SERVO-LEFT);
servo_right.attach(SERVO-RIGHT);
servoMove();
}
void servoMove() {
servo_left.write(0);
servo_right.write(180);
}
Test.h 0 → 100644
const char MAIN_page[] PROGMEM = R"=====(
<html>
<head>
<title>LEMUR Paper Boat</title>
<style>
h2 {
color: orange;
}
h3 {
color: #2274AF;
}
body {
background-color: black;
text-align: center;
color: white;
font-family: Arial, Helvetica, sans-serif;
}
.header{
padding: 20px;
text-align: center;
background: black;
color: white;
}
.button {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.button1 {
background-color: red;
}
table, th, td {
border: 1px solid black;
padding: 10px;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: black;
color: white;
text-align: center;
}
</style>
</head>
<div class="header">
<h1>Paper Boat</h1>
</div>
<body>
<button class="button">ON</button>
<button class="button button1">OFF</button>
<div class="table">
<table align="center">
<tr>
<th>&#8598;</th>
<th>&#8593;</th>
<th>&#8599;</th>
</tr>
<tr>
<td>&#8592;</td>
<td><img src="https://s7d2.scene7.com/is/image/Fathead/lgo_ncaa_ucla_bruins?layer=comp&fit=constrain&hei=300&wid=300&fmt=png-alpha&qlt=95,0&op_sharpen=1&resMode=bicub&op_usm=0.0,0.0,0,0&iccEmbed=0" alt="bruin" style="width:200px"></td>
<td>&#8594;</th>
</tr>
<tr>
<td>&#8601;</td>
<td>&#8595;</td>
<td>&#8600;</td>
</tr>
</table>
</div>
<div class="footer">
<h2>LEMUR</h2>
<h4>The Laboratory of Embedded Machines and Ubiquitous Robots</h4>
<h3>UCLA Electrical Engineering</h3>
</div>
</body>
</html>
)=====";
Test.ino 0 → 100644
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include "PaperBoat.h"
//SSID and Password of your WiFi router
const char* ssid = "Melissa's iPhone";
const char* password = "yelloooo";
ESP8266WebServer server(80); //Server on port 80
//===============================================================
// This routine is executed when you open its IP in browser
//===============================================================
void handleRoot() {
String s = MAIN_page; //Read HTML contents
server.send(200, "text/html", s); //Send web page
}
//==============================================================
// SETUP
//==============================================================
void setup(void){
Serial.begin(9600);
WiFi.begin(ssid, password); //Connect to your WiFi router
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
//If connection successful show IP address in serial monitor
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP()); //IP address assigned to your ESP
server.on("/", handleRoot); //Which routine to handle at root location
server.begin(); //Start server
Serial.println("HTTP server started");
}
//==============================================================
// LOOP
//==============================================================
void loop(void){
server.handleClient(); //Handle client requests
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment