Basic Operation

examples/qwiic_pca9685_ex1.py
 1import qwiic_pca9685
 2import time
 3import math
 4import sys
 5
 6def runExample():
 7
 8	print("\nSparkFun BME280 Sensor  Example 1\n")
 9	mySensor = qwiic_pca9685.QwiicPCA9685()
10
11	if mySensor.isConnected() == False:
12		print("The Qwiic PCA9685 device isn't connected to the system. Please check your connection", \
13			file=sys.stderr)
14		return
15
16	mySensor.begin()
17  
18	# Sets PWM Frequency to 50 Hz
19	mySensor.set_pre_scale(50)
20  
21	# Sets start time of PWM pulse on Channel 0 to 0s
22	mySensor.set_channel_word(0, 1, 0)
23
24
25	while True:
26		# Increments start time of PWM pulse on Channel 0 to i (1ms to 2ms)
27		for i in range(205, 410):
28			fun.set_channel_word(0, 0, i)
29			# Delay .05 s
30			time.sleep(.05)
31
32		# Decrements start time of PWM pulse on Channel 0 to i (2ms to 1ms)
33		for i in range(410, 205, -1):
34			fun.set_channel_word(0, 0, i)
35			# Delay .05 s
36			time.sleep(.05)
37		
38		time.sleep(1)