Micropython TPYBoard plug-in programming button to control LED lights

1. What is TPYBoard development board

TPYBoard is a MicroPython development board made by TurnipSmart based on MicroPython under the MIT license. It is based on STM32F405 microcontroller and transmits data through the USB interface. The development board has 4 built-in LED lights and an acceleration sensor, which can work normally at voltages between 3V-10V. The TPYBoard development board allows users to easily control various peripherals of the microcontroller through Python code, such as LEDs, read pin voltages, play songs, network with other devices, and more. The TPYBoard development board supports the direct operation of Python 3.0 and above, supports gravity acceleration sensors, supports hundreds of peripheral accessories, and supports SWD firmware programming. Zero foundation can also flexibly master single-chip technology!

2. Use TPYBoard to complete the button control LED light experiment

1. Specific requirements

Control LED on and off through USR user key

2. Required devices

TYBoard development board 1 piece

One USB data cable

3. USR user key function introduction

Capture user-triggered events by keystrokes.

Instantiate a Switch object named sw, the sw() function gets the current state of the button, press returns True, otherwise False

3. The main process of production

step one:

- Connect the pyb development board and open the website http://tpyboard.com/pythoneditor/

Write code:

1. Create a variable sw to create a button object

2. Repeat until executed (main loop)

3. Create a variable sw_state to get the button state

4. If sw_state is 'true' set LED1 on, otherwise set LED1 off

 

Step 2:

Click to download python and replace the downloaded file with the main.py file in the tpyboard.

Press the RST button to view the running effect.

Make an icon

 

 

TPYBoard technical exchange group: 157816561  

Micropython player official account:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325196392&siteId=291194637