:::
1. Arduino
(1)
D1 R32 pinout:https://bpb-ap-se2.wpmucdn.com/blogs.auckland.ac.nz/dist/9/698/files/2021/08/2_Pinout_D1_R32.png
D1 R32 參考文件:D1_R32_ENG.pdf
(2) 步進馬達
from machine import PWM, Pin
class Servo:
def __init__(self, pin, min=500, max=2400, range=180):
self.servo = PWM(Pin(pin), freq=50)
self.period = 20000
self.minDuty = self.__duty(min)
self.maxDuty = self.__duty(max)
self.unit = (self.maxDuty - self.minDuty)/range
def __duty(self, value):
return int(value/self.period * 1024)
def rotate(self, degree=90):
val = round(self.unit * degree) + self.minDuty
val = min(self.maxDuty, max(self.minDuty, val))
self.servo.duty(val)
(3) 網站連線控制 led 開啓
subWifiLed.py
def subWifiLed(ssid='MicroPython-AP', password='123456789'):
try:
import usocket as socket
except:
import socket
import network
ap = network.WLAN(network.AP_IF)
ap.active(True)
ap.config(essid=ssid, password=password)
while ap.active() == False:
pass
print('Connection successful')
print(ap.ifconfig())
def web_page():
html = """
Hello, World!
"""
return html
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5)
while True:
conn, addr = s.accept()
print('Got a connection from %s' % str(addr))
request = conn.recv(1024)
print('Content = %s' % str(request))
print(a.value(), 'favicon.ico' not in str(request))
#if 'GET /?led=' in str(request):
if 'favicon.ico' not in str(request):
if a.value() == 0:
a.value(1)
else:
a.value(0)
response = web_page()
conn.send(response)
conn.close()
main.py
import network
from machine import Pin
from time import sleep
a = Pin(2 ,Pin.OUT)
ssid = 'MicroPython-AP'
password = '123456789'
from subWifiLed import subWifiLed
subWifiLed('MicroPython-AP', a)
2. 軟體工程師的 AI 工具
Copilot:https://copilot.microsoft.com/
ChatGPT:https://chatgpt.com/
推薦給軟體工程師的 AI 工具:https://www.explainthis.io/zh-hant/pinthis/blog/swe-ai-tools
使用範例:
(1) 在 esp8266 d1 上用 micropython 點亮一個 LED
(2) 在 esp8266 d1 上用 micropython 控制一個 LED閃爍