> For the complete documentation index, see [llms.txt](https://teaching.gitbook.io/ee5127/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://teaching.gitbook.io/ee5127/lab/iot-device-programming/circuitpython-blink-program.md).

# CircuitPython Blink Program

Visual Studio Code is the recommended editor for CircuitPython and Python programming in this module.&#x20;

Download and install [Visual Studio Code](https://code.visualstudio.com/) on your laptop.

Install necessary Visual Studio Code (VS Code) extensions. These include "Python", "Visual Studio IntelliCode" from Microsoft and "[CircuitPython V2](https://marketplace.visualstudio.com/items?itemName=wmerkens.vscode-circuitpython-v2)". Restart VS Code after installing each extension.

<figure><img src="https://1642858864-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MW_pkggCd-D5nsvstvb%2Fuploads%2FIpvun8e1N4AAtcWPHmyX%2Fimage.png?alt=media&amp;token=55059073-93b5-4fdf-896b-8a2231da0e5c" alt=""><figcaption><p>Installing extensions in Visual Study Code </p></figcaption></figure>

Open `CIRCUITPY` directory in VS Code

<figure><img src="https://1642858864-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MW_pkggCd-D5nsvstvb%2Fuploads%2FBHaLJ5jTtC9p3nVWU8s0%2Fimage.png?alt=media&amp;token=900ed65e-6d9e-4175-9c30-4a327a434ff5" alt=""><figcaption></figcaption></figure>

Copy the following sample code to the `code.py` file. Create a `code.py` file if doesn't exist

```python
import board
import digitalio
import time

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

while True:
    led.value = True
    time.sleep(0.5)
    led.value = False
    time.sleep(0.5)
```

<figure><img src="https://1642858864-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MW_pkggCd-D5nsvstvb%2Fuploads%2Fee8Iqan8EMzv5Ipkg7JF%2Fimage.png?alt=media&amp;token=53f4787c-1bfa-496e-9cf9-48f9d2914012" alt=""><figcaption></figcaption></figure>

Save the `code.py` file on your `CIRCUITPY` drive. The little LED on the board should now be blinking as soon as you save the file provided that the Feahter board is connected and its name, Adafruit Industries LLC: Feather Bluefruit Sense, appears in the bottom right corner of VSCode.

{% hint style="info" %}
Note that under the `while True:` line, the next four lines begin with four spaces to indent them, and they're indented exactly the same amount. All the lines before that have no spaces before the text.
{% endhint %}

{% hint style="info" %}
The CircuitPython code on your board detects when the files are changed or written and will automatically run your code from the start. If you unplug or reset the board before your computer finishes writing the file to your board, you can corrupt the drive.
{% endhint %}

It is a good idea to save the workspace in `CIRCUITPY` drive using `File > Save Workspace as` option. You can give any name to the workspace or simply `feather-sense.code-workspace`.

### References and Acknowledgement

This page is an edited version of [Creating and Editing Code](https://learn.adafruit.com/welcome-to-circuitpython/creating-and-editing-code) published by Kattni Rembor in the [Welcome to CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/overview) guide on the Adafruit website.
