Porównaj commity

...

12 Commity

Autor SHA1 Wiadomość Data
Alasdair Allan 35f9a54463
Merge pull request #62 from tobybroberts/patch-2
Revert "LED" to Pin 25
2023-03-01 16:13:32 +00:00
Toby Roberts 4663e8c922
Revert "LED" to Pin 25 2023-03-01 16:11:40 +00:00
Alasdair Allan 93b03d8b3a
Merge pull request #60 from tobybroberts/patch-1
Changed Pin 25 to "LED"
2023-03-01 15:54:16 +00:00
Alasdair Allan 5a823b14c5 added webserver example 2023-03-01 15:53:15 +00:00
Toby Roberts 07a5c25dae
Revert to Pin 25 from "LED" 2023-02-28 14:08:54 +00:00
Toby Roberts 4edbf0e18a
Revert to Pin 25 from "LED" 2023-02-28 14:07:55 +00:00
Toby Roberts 18ee8b84e5
Revert to Pin 25 from LED 2023-02-28 14:06:31 +00:00
Toby Roberts 036f6a1433
Changed Pi 25 to "LED" 2023-02-28 13:33:26 +00:00
Toby Roberts d5be37bae4
Changed Pin 25 to "LED" 2023-02-28 13:31:06 +00:00
Toby Roberts 38af55dc13
Changed Pin 25 to "LED" 2023-02-28 13:29:55 +00:00
Toby Roberts 10f07acf74
Changed Pin 25 to "LED" 2023-02-28 12:48:28 +00:00
Toby Roberts 2a52d769f8
Changed Pin 25 to "LED" 2023-02-28 11:59:47 +00:00
5 zmienionych plików z 84 dodań i 4 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -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.

Wyświetl plik

@ -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.

Wyświetl plik

@ -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:

Wyświetl plik

@ -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')