Porównaj commity
12 Commity
c82971b6e0
...
35f9a54463
Autor | SHA1 | Data |
---|---|---|
Alasdair Allan | 35f9a54463 | |
Toby Roberts | 4663e8c922 | |
Alasdair Allan | 93b03d8b3a | |
Alasdair Allan | 5a823b14c5 | |
Toby Roberts | 07a5c25dae | |
Toby Roberts | 4edbf0e18a | |
Toby Roberts | 18ee8b84e5 | |
Toby Roberts | 036f6a1433 | |
Toby Roberts | d5be37bae4 | |
Toby Roberts | 38af55dc13 | |
Toby Roberts | 10f07acf74 | |
Toby Roberts | 2a52d769f8 |
|
@ -1,7 +1,7 @@
|
|||
import time, _thread, machine
|
||||
|
||||
def task(n, delay):
|
||||
led = machine.Pin(25, machine.Pin.OUT)
|
||||
led = machine.Pin("LED", machine.Pin.OUT)
|
||||
for i in range(n):
|
||||
led.high()
|
||||
time.sleep(delay)
|
||||
|
|
|
@ -19,7 +19,7 @@ def blink():
|
|||
nop() [31]
|
||||
wrap()
|
||||
|
||||
# Instantiate a state machine with the blink program, at 2000Hz, with set bound to Pin(25) (LED on the rp2 board)
|
||||
# Instantiate a state machine with the blink program, at 2000Hz, with set bound to Pin(25) (LED on the Pico board)
|
||||
sm = rp2.StateMachine(0, blink, freq=2000, set_base=Pin(25))
|
||||
|
||||
# Run the state machine for 3 seconds. The LED should blink.
|
||||
|
|
|
@ -14,7 +14,7 @@ def prog():
|
|||
pass
|
||||
|
||||
|
||||
# Construct the StateMachine, binding Pin(25) to the set pin.
|
||||
# Construct the StateMachine, binding Pin 25 to the set pin.
|
||||
sm = rp2.StateMachine(0, prog, set_base=Pin(25))
|
||||
|
||||
# Turn on the set pin via an exec instruction.
|
||||
|
|
|
@ -34,7 +34,7 @@ class PIOPWM:
|
|||
self._sm.put(value)
|
||||
|
||||
|
||||
# Pin 25 is LED on Pico boards
|
||||
# Pin 25 on Pico boards
|
||||
pwm = PIOPWM(0, 25, max_count=(1 << 16) - 1, count_freq=10_000_000)
|
||||
|
||||
while True:
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
import network
|
||||
import socket
|
||||
import time
|
||||
|
||||
from machine import Pin
|
||||
|
||||
led = Pin(15, Pin.OUT)
|
||||
|
||||
ssid = 'YOUR NETWORK NAME'
|
||||
password = 'YOUR NETWORK PASSWORD'
|
||||
|
||||
wlan = network.WLAN(network.STA_IF)
|
||||
wlan.active(True)
|
||||
wlan.connect(ssid, password)
|
||||
|
||||
html = """<!DOCTYPE html>
|
||||
<html>
|
||||
<head> <title>Pico W</title> </head>
|
||||
<body> <h1>Pico W</h1>
|
||||
<p>%s</p>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
max_wait = 10
|
||||
while max_wait > 0:
|
||||
if wlan.status() < 0 or wlan.status() >= 3:
|
||||
break
|
||||
max_wait -= 1
|
||||
print('waiting for connection...')
|
||||
time.sleep(1)
|
||||
|
||||
if wlan.status() != 3:
|
||||
raise RuntimeError('network connection failed')
|
||||
else:
|
||||
print('connected')
|
||||
status = wlan.ifconfig()
|
||||
print( 'ip = ' + status[0] )
|
||||
|
||||
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
|
||||
|
||||
s = socket.socket()
|
||||
s.bind(addr)
|
||||
s.listen(1)
|
||||
|
||||
print('listening on', addr)
|
||||
|
||||
# Listen for connections
|
||||
while True:
|
||||
try:
|
||||
cl, addr = s.accept()
|
||||
print('client connected from', addr)
|
||||
request = cl.recv(1024)
|
||||
print(request)
|
||||
|
||||
request = str(request)
|
||||
led_on = request.find('/light/on')
|
||||
led_off = request.find('/light/off')
|
||||
print( 'led on = ' + str(led_on))
|
||||
print( 'led off = ' + str(led_off))
|
||||
|
||||
if led_on == 6:
|
||||
print("led on")
|
||||
led.value(1)
|
||||
stateis = "LED is ON"
|
||||
|
||||
if led_off == 6:
|
||||
print("led off")
|
||||
led.value(0)
|
||||
stateis = "LED is OFF"
|
||||
|
||||
response = html % stateis
|
||||
|
||||
cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
|
||||
cl.send(response)
|
||||
cl.close()
|
||||
|
||||
except OSError as e:
|
||||
cl.close()
|
||||
print('connection closed')
|
Ładowanie…
Reference in New Issue