Created
September 2, 2024 07:52
-
-
Save robvdl/8d1205ee2a083f073687563337107c3e to your computer and use it in GitHub Desktop.
Unexpected Maker FeatherS3 example converted from CircuitPython to MicroPython
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gc | |
import os | |
import time | |
# The "board" import doesn't exist and the digitalio import was unused and doesn't exist either | |
# import board, digitalio | |
import machine | |
import neopixel | |
# Don't copy feathers3.py to the board, it already exists in MicroPython. | |
import feathers3 | |
# Create a NeoPixel instance | |
# Some of the initialisation parameters like brightness and auto_write don't exist in MicroPython. | |
# Brightness of 0.3 is ample for the 1515 sized LED | |
# pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.3, auto_write=True, pixel_order=neopixel.RGB) | |
pixel = neopixel.NeoPixel(machine.Pin(feathers3.RGB_DATA), 1) | |
# Say hello | |
print("\nHello from FeatherS3!") | |
print("------------------\n") | |
# Show available memory | |
print("Memory Info - gc.mem_free()") | |
print("---------------------------") | |
print("{} Bytes\n".format(gc.mem_free())) | |
flash = os.statvfs('/') | |
flash_size = flash[0] * flash[2] | |
flash_free = flash[0] * flash[3] | |
# Show flash size | |
print("Flash - os.statvfs('/')") | |
print("---------------------------") | |
print("Size: {} Bytes\nFree: {} Bytes\n".format(flash_size, flash_free)) | |
print("Pixel Time!\n") | |
# Create a colour wheel index int | |
color_index = 0 | |
# Turn on the power to the NeoPixel | |
feathers3.set_ldo2_power(True) | |
# Rainbow colours on the NeoPixel | |
while True: | |
# Get the R,G,B values of the next colour | |
r,g,b = feathers3.rgb_color_wheel( color_index ) | |
# Set the colour on the NeoPixel | |
# pixel[0] = ( r, g, b, 0.5) | |
# In MicroPython we need to calculate the brightness ourselves | |
pixel.fill((int(round(r * 0.5)), int(round(g * 0.5)), int(round(b * 0.5)))) | |
pixel.write() | |
# Increase the wheel index | |
color_index += 1 | |
# If the index == 255, loop it | |
if color_index == 255: | |
color_index = 0 | |
# Invert the internal LED state every half colour cycle | |
feathers3.led_blink() | |
# Sleep for 15ms so the colour cycle isn't too fast | |
time.sleep(0.015) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment