Flashing the onboard LEDs on a PyBoard

The Pyboard comes with 4 on board LEDs, in this example we will flash them on and off, the example was written in uPyCraft

 

Pinouts

 

Parts List

Name Link
Elecrow PyBoard Elecrow Core Board For MicroPython Crow Pyboard Development Board STM32F405RG for Pyboard Python Learning Module Microcontroller

Code

First of all the various methods from the official docs

LED.intensity([value])
Get or set the LED intensity. Intensity ranges between 0 (off) and 255 (full on). If no argument is given, return the LED intensity. If an argument is given, set the LED intensity and return None.

Note: Only LED(3) and LED(4) can have a smoothly varying intensity, and they use timer PWM to implement it. LED(3) uses Timer(2) and LED(4) uses Timer(3). These timers are only configured for PWM if the intensity of the relevant LED is set to a value between 1 and 254. Otherwise the timers are free for general purpose use.

LED.off()
Turn the LED off.
LED.on()
Turn the LED on, to maximum intensity.
LED.toggle()
Toggle the LED between on (maximum intensity) and off. If the LED is at non-zero intensity then it is considered “on” and toggle will turn it off.

Now for the example showing this

from pyb import LED
import time
 
led1 = LED(1) # 1=red, 2=green, 3=yellow, 4=blue
led1.toggle()
led1.on()
time.sleep(1)
led1.off()
time.sleep(1)
 
led2 = LED(2) # 1=red, 2=green, 3=yellow, 4=blue
led2.toggle()
led2.on()
time.sleep(1)
led2.off()
time.sleep(1)
 
led3 = LED(3) # 1=red, 2=green, 3=yellow, 4=blue
led3.toggle()
led3.on()
time.sleep(1)
led3.off()
time.sleep(1)
 
led4 = LED(4) # 1=red, 2=green, 3=yellow, 4=blue
led4.toggle()
led4.on()
time.sleep(1)
led4.off()
time.sleep(1)
 
# LEDs 3 and 4 support PWM intensity (0-255)
LED(4).intensity()    # get intensity
LED(4).intensity(25) # set intensity to 25
Share

Comments are closed.