最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

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

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用網頁控制舵機實現遠程開關燈(代碼部分)的評論 (共 條)

分享到微博請遵守國家法律
蒙自县| 江北区| 慈溪市| 蓬溪县| 邢台市| 德阳市| 郴州市| 屏南县| 邢台市| 石泉县| 柞水县| 宁波市| 洞头县| 栖霞市| 晋中市| 彰化县| 上虞市| 建水县| 潼南县| 鹤庆县| 夏河县| 南开区| 耒阳市| 儋州市| 华安县| 延边| 虞城县| 大宁县| 威远县| 土默特右旗| 玉树县| 遂平县| 桃园县| 绩溪县| 合阳县| 松阳县| 巴塘县| 涿州市| 台东市| 集贤县| 内黄县|