安装环境
地址:https://arduino.esp8266.com/stable/package_esp8266com_index.json
连接WIFI并且创建Web服务器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include <ESP8266WiFi.h>
const char* ssid = "Test-WIFI"; const char* pwd = "wifi password";
WiFiServer server(80);
void setup() { Serial.begin(115200); WiFi.begin(ssid, pwd); while(WiFi.status() != WL_CONNECTED){ delay(500); Serial.print("."); } Serial.print(""); Serial.println("wifi已连接!!!"); server.begin(); Serial.print(WiFi.localIP()); }
void loop() { WiFiClient client = server.available(); if(!client){ return; }
while(!client.available()){ delay(1); }
String s = "<h1>Hello ESP8266!</h1><script>open('http://yuan67.top');</script>"; client.print(s); delay(1); Serial.println("客户端已响应!"); }
|
LED等由亮到灭,由灭到亮1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| int LED = 2; void setup() { pinMode(LED,OUTPUT); }
void loop() { for(int i=0;i<=1023;i++){ analogWrite(LED, i); delay(2); } for(int i=1023;i>=0;i--){ analogWrite(LED, i); delay(1); } }
|