Setup Adafruit GEMMA M0 for CircuitPython
Your GEMMA M0 should already come with CircuitPython but maybe there's a new version, or you overwrote your board with Arduino code! In that case, see the below for how to reinstall or update CircuitPython. Otherwise you can skip this and go straight to the next page.
Upload The Code
Copy and paste the code below into a new text document (we recommend using Mu as your editor, which is designed for CircuitPython.). Save the file and name it as main.py
Once the files has been uploaded to the drive, the board will automatically reboot and run the code.
import time import board import pulseio from digitalio import DigitalInOut, Direction # PWM (fading) LEDs are connected on D0, D2 (PWM not avail on D1) pwm_leds = board.D2 pwm = pulseio.PWMOut(pwm_leds, frequency=1000, duty_cycle=0) pwm2_leds = board.D0 pwm2 = pulseio.PWMOut(pwm2_leds, frequency=1000, duty_cycle=0) brightness = 0 # how bright the LED is fade_amount = 1285 # 2% steping of 2^16 counter = 0 # counter to keep track of cycles while True: # And send to LED as PWM level pwm.duty_cycle = brightness pwm2.duty_cycle = brightness # change the brightness for next time through the loop: brightness = brightness + fade_amount print(brightness) # reverse the direction of the fading at the ends of the fade: if brightness <= 0: fade_amount = -fade_amount counter += 1 elif brightness >= 65535: fade_amount = -fade_amount counter += 1 # wait for 15 ms to see the dimming effect time.sleep(.015)
Page last edited March 08, 2024
Text editor powered by tinymce.