Brandon,
Thank you for your help and pardon my ignorance. I do not understand what it means for the master to be ‘off’. Is the off/on determined by SEL wired to the pca.channels[0]? Does ‘off’ mean only the master is passed; does this imply that ‘on’ means the slave is passed? How do I set the slave to be passed to out? Is this done by decreasing the duty_cycle below 1696? I have read the manual, but I do not understand the implied meaning of many points discussed.
I did not intend the slave to float. The pca9685 channels[2] and channels[3] are wired to s2 and s3, with leds on out2 and out3. Is that how it works?
I have pca.channels[1] wired to M1 and channels[4] to M4, with leds on out1 and out4.
# Code:
from adafruit_pca9685 import PCA9685
import board
import busio
import time
import signal
import sys
# Create I2C bus
i2c = busio.I2C(board.SCL, board.SDA)
# Create PCA9685 instance
pca = PCA9685(i2c)
pca.frequency = 50 # 50Hz frequency PWM
pca.channels[0].duty_cycle = 106*16 # 1696 duty cycle
# Ensure both LEDs are off
pca.channels[1].duty_cycle = 0
pca.channels[2].duty_cycle = 0
pca.channels[3].duty_cycle = 0
pca.channels[4].duty_cycle = 0
# Initialize LEDs
def initialize_leds():
pca.channels[1].duty_cycle = 0 # OFF for OUT1 (master)
pca.channels[2].duty_cycle = 0 # OFF for OUT2 (slave)
pca.channels[3].duty_cycle = 0 # OFF for OUT3 (slave)
pca.channels[4].duty_cycle = 0 # OFF for OUT4 (master)
print("LEDs Off")
initialize_leds()
# Cleanup function on Ctrl+C
def signal_handler(sig, frame):
initialize_leds()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
# Function to blink LEDs
def blink_leds():
while True:
pca.channels[4].duty_cycle = 2048 # Turn ON Master LED, M4 to OUT4, blue
print("master 4, blue ON")
time.sleep(1)
pca.channels[4].duty_cycle = 0
pca.channels[3].duty_cycle = 2048 # Turn ON Slave LED, S3 to OUT3, red
print("slave 3, red ON")
time.sleep(1)
pca.channels[3].duty_cycle = 0
# set_default_valid_signal()
pca.channels[2].duty_cycle = 2048 # Turn ON Slave LED, S2 to OUT2, green
print("slave 2, green ON")
time.sleep(1)
pca.channels[2].duty_cycle = 0
pca.channels[1].duty_cycle = 2048 # Turn ON Master LED, M1 to OUT1, white
print("master 1, white ON")
time.sleep(1)
pca.channels[1].duty_cycle = 0
# time.sleep(1)
# Run the test
blink_leds()
Thanks,
