国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網 會員登陸 & 注冊

micropython驅動esp32用網頁控制舵機實現遠程開關燈(代碼部分)

2022-08-31 11:03 作者:洋洋柚Y  | 我要投稿

在給esp燒錄好固件之后,分別寫入boot.py和main.py以及html.html。

=======================================================

boot.py:

def hotlink(name='wifiname',pd='12345678'):#開發(fā)板開熱點方式

? ? try:

? ? ? ? import network

? ? ? ? hot = network.WLAN(network.AP_IF)

? ? ? ? hot.active(True)

? ? ? ? hot.config(essid=name)

? ? ? ? hot.config(authmode=3, password=pd)

? ? except:

? ? ? ? print('hotlink has fall')

? ? ? ??

def do_connect(name,password):#開發(fā)板連接路由器方式

? ? import network

? ? wifi = network.WLAN(network.STA_IF)

? ? if not wifi.isconnected():

? ? ? ? print('正在連接wifi')

? ? ? ? wifi.active(True) #激活WIFI

? ? ? ? wifi.connect(name, password)

? ? ? ? while not wifi.isconnected():

? ? ? ? ? ? pass?

? ? print('network config:', wifi.ifconfig())

hotlink('esp','12345678')#在這里我們暫時用開發(fā)板開熱點方式舉例

=======================================================

main.py:


from machine import Pin,PWM

import socket

import time


cod=1.6

State = str((cod-1.6)*10) + '度'


a1 = PWM(Pin(15),freq=50)#舵機信號接口(這里接的是開發(fā)板GPIO15)

a1.duty(int((1.6)/20*1023))#0.3~2.6(0.6~2.6為0到180度)

#for i in range(27):#測試舵機

#? ? a1.duty(int((0.1*i)/20*1023))

#? ? time.sleep(0.5)

#? ? print(i)

html = open('html.html','r')

html = html.read()

addr = socket.getaddrinfo('192.168.4.1', 80)[0][-1]#板子自己開熱點默認ip

#如果用連接熱點方式則要用路由器分配的IP地址

s = socket.socket()

s.bind(addr)

s.listen(1)


print('listening on', addr)


while(True):

? ? cl, addr = s.accept()

? ? print(addr)

? ? data = cl.recv(100)

? ? if data.decode()[:20].find("+1") != -1:

? ? ? ? if(cod<2.5):

? ? ? ? ? ? cod = cod+0.1

? ? ? ? ? ? time.sleep(0.1)

? ? ? ? ? ? a1.duty(int((cod)/20*1023))

? ? ? ? ? ? time.sleep(0.1)

? ? ? ? ? ? State = str(int((cod-1.6)*100)) + '度'

? ? elif data.decode()[:20].find("-1") != -1:

? ? ? ? if(cod>=0.4):

? ? ? ? ? ? cod = cod-0.1

? ? ? ? ? ? time.sleep(0.1)

? ? ? ? ? ? a1.duty(int((cod)/20*1023))

? ? ? ? ? ? time.sleep(0.1)

? ? ? ? ? ? State = str(int((cod-1.6)*100)) + '度'

? ? print(cod)

? ? response = html % State

? ? cl.send(response)

? ? time.sleep(0.1)

? ? cl.close()

=======================================================

html.html:


? ? <!DOCTYPE html>

<html>

? ? <head>

? ? ? ? <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

? ? ? ? <title>舵機控制器</title>

? ? </head>

? ? <body>?

? ? ? ? <font size="100">當前狀態(tài) : %s </font>

? ? ? ? <br><br>

? ? ? ? <a href=\"/+1\"\"> <button style="height:200px;width:300px;background:pink;"> <font size="100">加10度<font></button></a>

? ? ? ? <a href=\"/-1\"\"><button style="height:200px;width:300px;background:white;" > <font size="100">減10度<font></button></a><br />?

? ? </body>

</html>

=======================================================

請參考:https://www.bilibili.com/video/BV1PT411c711?spm_id_from=333.999.0.0




micropython驅動esp32用網頁控制舵機實現遠程開關燈(代碼部分)的評論 (共 條)

分享到微博請遵守國家法律
霸州市| 琼结县| 嘉鱼县| 周口市| 灵川县| 灵石县| 元谋县| 通江县| 龙岩市| 濮阳县| 正蓝旗| 伽师县| 内乡县| 黑山县| 新乐市| 若尔盖县| 上犹县| 宣武区| 宾阳县| 江都市| 韩城市| 绥芬河市| 苏尼特右旗| 都安| 仲巴县| 浦东新区| 冕宁县| 内丘县| 昭通市| 新宁县| 渭源县| 深圳市| 西乌珠穆沁旗| 赤壁市| 宾川县| 义马市| 鄯善县| 武冈市| 垫江县| 德格县| 习水县|