# 0527課程筆記 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> # 0513課程筆記 ```arduino= void setup() { Serial.begin(115200); pinMode(D2,OUTPUT); } void loop() { // put your main code here, to run repeatedly: digitalWrite(D2,1); // 亮 delay(1000); digitalWrite(D2,0); // 暗 delay(1000); } ``` home.h ```arduino= const char PAGE_INDEX[] PROGMEM = R"=====( <html> <head> <style> div{ height:400px; width:300px; position:absolute; left:40%; top:100px; text-align:center; } #button1{ background-color: #4CAF50; color: white; } #button1:hover { background-color: white; color: black; border: 2px solid #4CAF50; } #button2{ background-color: #f44336; color: white; } #button2:hover { background-color: white; color: black; border: 2px solid #f44336; } button{ width:80px; height:40px } </style> <body> <div> <h1>網頁控制</h1> <p>目前燈號狀態 <li>LED1:Off</li> <li>LED2:Off</li> <p> <p> <a href="/LEDOn"><button id="button1">Turn On LED1</button></a> <a href="/LEDOff"><button id="button2">Turn Off LED1</button></a> </p> <p> <a href="/LEDOn"><button id="button1">Turn On LED2</button></a> <a href="/LEDOff"><button id="button2">Turn Off LED2</button></a> </p> </div> </body> </html> )====="; ``` ## 第一組 ``` arduino #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #define LED_PIN D2 const char* ssid = "Hamster"; const char* password = "test1234"; ESP8266WebServer server(80); void setup() { pinMode(D2,OUTPUT); //設定D2為輸出腳位 Serial.begin(115200); //監控視窗設定鮑率為 115200 WiFi.begin(ssid, password); //啟動wifi Serial.println(""); // Wait for connection while (WiFi.status() != WL_CONNECTED) { //如果未連線 delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); //得到網路IP server.on("/", []() { // 首頁 server.send(200, "text/html", "首頁的html放這裡"); }); server.on("/LEDOn", []() { //led亮 digitalWrite(D2, 1); server.send(200, "text/html", "led亮的html放這裡"); }); server.on("/LEDOff", []() { //led暗 digitalWrite(D2, 0); server.send(200, "text/html", "led暗的html放這裡"); }); server.begin(); Serial.println("HTTP server started"); } void loop() { server.handleClient(); //持續發送服務 } ``` ## 第二組 ``` arduino #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #define LED_PIN D2 const char* ssid = "test12345"; const char* password = "test1234"; ESP8266WebServer server(80); void setup() { pinMode(D2,OUTPUT); //設定D2為輸出腳位 Serial.begin(115200); //監控視窗設定鮑率為 115200 WiFi.begin(ssid, password); //啟動wifi Serial.println(""); // Wait for connection while (WiFi.status() != WL_CONNECTED) { //如果未連線 delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); //得到網路IP server.on("/", []() { // 首頁 String s = "<html><body><h1>ESP8266 Web Server</h1>"; s += "<p><a href=\"/LEDOn\"><button>Turn On</button></a></p>"; s += "<p><a href=\"/LEDOff\"><button>Turn Off</button></a></p>"; s += "</body></html>"; server.send(200, "text/html", s); }); server.on("/LEDOn", []() { digitalWrite(D2, 1); server.send(200, "text/html", "<html><body><h1>LED is On</h1><p><a href=\"/\">Back</a></p></body></html>"); }); server.on("/LEDOff", []() { digitalWrite(D2, 0); server.send(200, "text/html", "<html><body><h1>LED is Off</h1><p><a href=\"/\">Back</a></p></body></html>"); }); server.begin(); Serial.println("HTTP server started"); } void loop() { server.handleClient(); //持續發送服務 } ``` ## 第三組 ``` arduino #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #define LED_PIN D2 const char* ssid = "test1234"; const char* password = "test1234"; ESP8266WebServer server(80); void setup() { pinMode(D2,OUTPUT); //設定D2為輸出腳位 Serial.begin(115200); //監控視窗設定鮑率為 115200 WiFi.begin(ssid, password); //啟動wifi Serial.println(""); // Wait for connection while (WiFi.status() != WL_CONNECTED) { //如果未連線 delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); //得到網路IP server.on("/", []() { // 首頁 String s = "<html><body><h1>ESP8266 Web Server</h1>"; s += "<p><a href=\"/LEDOn\"><button>Turn On</button></a></p>"; s += "<p><a href=\"/LEDOff\"><button>Turn Off</button></a></p>"; s += "</body></html>"; server.send(200, "text/html", s); }); server.on("/LEDOn", []() { digitalWrite(D2, 1); server.send(200, "text/html", "<html><body><h1>LED is On</h1><p><a href=\"/\">Back</a></p></body></html>"); }); server.on("/LEDOff", []() { digitalWrite(D2, 0); server.send(200, "text/html", "<html><body><h1>LED is Off</h1><p><a href=\"/\">Back</a></p></body></html>"); }); server.begin(); Serial.println("HTTP server started"); } void loop() { server.handleClient(); //持續發送服務 } ``` ``` html <html> <head> <style> #A{ color:blue; font-size: } #B{ color:green; } #C{ color:red; } div{ background-color:yellow; height:400px; width:600px; } </style> </head> <body> <p id='A'>Text</p> <p id='B'>Text</p> <p id='C'>Text</p> </body> </html> ``` ``` html <head> <style> #card{ background-color:gray; width:500px; position:absolute; left:10px; } </style> </head> ``` ``` html body{ background-image:url("img_HD/img06.jpg"); } ```