HM-10/11 attempt for history
This commit is contained in:
parent
a1e868017a
commit
c962c0bd6b
23
ch-9/1-hm-ble-basics/1-detect-device/code.py
Normal file
23
ch-9/1-hm-ble-basics/1-detect-device/code.py
Normal file
@ -0,0 +1,23 @@
|
||||
import board
|
||||
from digitalio import DigitalInOut
|
||||
import time
|
||||
import busio
|
||||
|
||||
led = DigitalInOut(board.LED)
|
||||
led.switch_to_output()
|
||||
|
||||
# PICO UART pins? What am i not using?
|
||||
uart = busio.UART(board.GP12,board.GP13,baudrate=9600)
|
||||
|
||||
while True:
|
||||
data = uart.read(32)
|
||||
|
||||
if data is not None:
|
||||
print(data)
|
||||
data_string = ''.join([chr(b) for b in data])
|
||||
if data_string=='1':
|
||||
led.value = True
|
||||
uart.write('on')
|
||||
if data_string=='0':
|
||||
led.value = False
|
||||
uart.write('off')
|
||||
20
ch-9/1-hm-ble-basics/2-through-pico-serial/code.py
Normal file
20
ch-9/1-hm-ble-basics/2-through-pico-serial/code.py
Normal file
@ -0,0 +1,20 @@
|
||||
import board
|
||||
from digitalio import DigitalInOut
|
||||
import time
|
||||
import busio
|
||||
import supervisor
|
||||
|
||||
led = DigitalInOut(board.LED)
|
||||
led.switch_to_output()
|
||||
|
||||
# PICO UART pins? What am i not using?
|
||||
uart = busio.UART(board.GP12,board.GP13,baudrate=9600)
|
||||
|
||||
while True:
|
||||
data = uart.read(32)
|
||||
if supervisor.runtime.serial_bytes_available:
|
||||
value = input().strip()
|
||||
print(f"Received: {value}\r")
|
||||
uart.write(value.encode())
|
||||
if data is not None:
|
||||
print(data)
|
||||
Loading…
x
Reference in New Issue
Block a user