The code initializes an OLED display and a BLE (Bluetooth Low Energy) module. It retrieves the MAC address of the BLE module and displays it on the OLED screen. It then toggles an LED on and off every 500 milliseconds and sends the string 'Hello World' to the BLE module every 500 milliseconds.

# main.py -- put your code here!
from pyb import Pin,LED,UART,OLED,delay

# Create OLED Object
oled=OLED()
# Clear OLED
oled.fill(0)
oled.show()

# Create BLE Object
ble = UART('BLE')
# Initialize BLE
ble.init(57600, bits=8, parity=None, stop=1, timeout=100)
# Set to AT Mode
ble.write('+++a')
ble.read(10)
# Get BLE MAC
ble.write('AT+MAC?
')
mac = ble.read(100)[7:19]
# Set to Transparent Mode
ble.write('AT+Z
')
ble.read(100)

# OLED Show MAC
oled.text('MAC:',0,0,1)
oled.text(mac,0,12,1)
oled.show()

led1 = LED(1)
led1.on()

while True:
    led1.off()
    delay(500)
    led1.on()
    delay(500)
    ble.write('Hello World\n')
    delay(500)

原文地址: https://www.cveoy.top/t/topic/o4Pp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录