-
Notifications
You must be signed in to change notification settings - Fork 1
Sample Workflow 1
This is a work in progress
This example consists of a single file (main.py) that is created and tested using Visual Studio Code and the MPRemote extension. The purpose is to a simple example of managing a project. To follow along, you will need the following:
- A microcontroller flashed with the latest MicroPython version
- A development host with Visual Studio Code and the MPRemote extension installed
The example was written using an ESP32-S3-DevKitC-1-N8 and MicroPython 1.20
When working through this example, you will use VS Code to create the MicroPython code on a development host. You will then upload the code to the microcontroller. Any changes are made on the local copy first and then uploaded.
Working this way ensures the "golden copy" of the code always resides on the development host.
Start Visual Studio Code on your development host and click the snake icon in the action pane (far left side). You will see a brief description of how to get started with the extension. Let's focus on the first step, opening the project folder.
- Click the Open Folder button
- Browse to an existing empty directory or click New Folder in the dialog box to create a new one.
- Click Open Folder
Notice how the empty folder is now open in Visual Studio Code's Explorer pane.
- Hover your mouse over the name of your project folder in the Explorer pane.
- Click the icon for New File.
- Name the file main.py.
Notice how the file opens in a new editor window. Copy the following code and paste it in the empty editor window.
# Traffic light example using built-in NeoPixel on an ESP32 DevKit board.
from machine import Pin
from neopixel import NeoPixel
from time import sleep
GPIO = 48 # Check ESP32 board silkscreen for the NeoPixel's GPIO number.
rgb = NeoPixel(Pin(GPIO), 1)
while True:
print("Red light (stop)")
rgb[0] = (8, 0, 0) # Red, green, blue values. Range 0..255
rgb.write()
sleep(15)
print("Green light (go)")
rgb[0] = (0, 8, 0)
rgb.write()
sleep(12)
print("Amber light (caution)")
rgb[0] = (8, 3, 0)
rgb.write()
sleep(3)
Figure 1: Using the NeoPixel as a traffic light.