Counter and LED Theme Toggle - Circuitpython Typing CST Test
Loading…
Counter and LED Theme Toggle — Circuitpython Code
Demonstrates a simple counter with theme toggling using CircuitPython variables and microcontroller GPIO control (LED indicator).
import board
import digitalio
count = 0
isDark = False
led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT
def updateUI():
print(f"Counter: {count}")
if isDark:
led.value = True
print("Theme: Dark")
else:
led.value = False
print("Theme: Light")
def increment():
global count
count += 1
updateUI()
def decrement():
global count
count -= 1
updateUI()
def reset():
global count
count = 0
updateUI()
def toggleTheme():
global isDark
isDark = not isDark
updateUI()
# Simulate actions
updateUI()
increment()
increment()
toggleTheme()
decrement()
reset()Circuitpython Language Guide
CircuitPython is an open-source derivative of MicroPython, designed by Adafruit to simplify programming microcontrollers for beginners and makers. It emphasizes easy setup, rapid prototyping, and accessible hardware interaction with Python.
Primary Use Cases
- ▸Educational programming for beginners
- ▸Prototyping embedded electronics projects
- ▸Interactive art and maker projects
- ▸Home automation with microcontrollers
- ▸Quick testing of sensors and hardware modules
Notable Features
- ▸Easy-to-use Python APIs for hardware
- ▸Cross-platform USB support for code editing
- ▸Automatic code execution on device boot
- ▸Wide library support for sensors and peripherals
- ▸Interactive REPL for real-time experimentation
Origin & Creator
Created by Adafruit Industries in 2017, based on MicroPython, to make Python accessible for beginners working with microcontrollers.
Industrial Note
CircuitPython is primarily educational and hobbyist-focused, though it can also be used for light industrial prototyping and interactive installations.