Demo Source Code

The Python source code of this demo is provided for reference purpose only.

RPi_demo_#PWM#_run_on_VisionFive.py
#import RPi.GPIO as GPIO
#*******************************************************
#Note: above command must be replaced with command below
import VisionFive.gpio as GPIO
#*******************************************************
from time import sleep

ledpin = 36				# PWM pin connected to LED
GPIO.setwarnings(False)		    # disable warnings
GPIO.setmode(GPIO.BOARD)		   # set pin numbering system
GPIO.setup(ledpin,GPIO.OUT)
pi_pwm = GPIO.PWM(ledpin,1000)		# create PWM instance with frequency
pi_pwm.start(0)			       # start PWM of required duty cycle 
while True: 
    for duty in range(0,101,1):
        pi_pwm.ChangeDutyCycle(duty)          # provide duty cycle in the range 0-100
        sleep(0.01)
    sleep(0.5)
    
    for duty in range(100,-1,-1):
        pi_pwm.ChangeDutyCycle(duty)
        sleep(0.01)
    sleep(0.5)