With this project we will manage a LED, using the FTDI FT232H development board (of which there is a dedicated page on this site) and the NXP PCA9685 development board (of which there is a dedicated page on this site).
This LED must be connected to the NXP PCA9685 development board. The connection connectors are listed below:
Image | Board FT232H | Board PCA9685 | LED |
---|---|---|---|
AD0 | SCL | ------ | |
AD1 + AD2 | SDA | ------ | |
+3.3V | VCC | ------ | |
GND | GND | ------ | |
------ | Channel 0 - PWM | Anode | |
------ | Channel 0 - GND | Cathode |
To manage this LED, the presence of the "PCA9685_FTDI" library is required.
The following Python code example turns the LED on/off and then creates a color flow:
import time import pca9685_ftdi # Create library object using our FTDI I2C port pwm = pca9685_ftdi.PCA9685_FTDI() STEP = 2 FACTOR = 4 SLEEP = 0 CHANNEL = 0 try: while True: print("\nLED on") pwm.setPWM(CHANNEL, 0, 256 * FACTOR) time.sleep(5) print("LED off") pwm.setPWM(CHANNEL, 0, 0) time.sleep(5) print("\nLED Flow") for fadeValue in range(0, 256, STEP): pwm.setPWM(CHANNEL, 0, fadeValue * FACTOR) time.sleep(SLEEP) print("LED Flow - Reverse") for fadeValue in range(255, -STEP, -STEP): pwm.setPWM(CHANNEL, 0, fadeValue * FACTOR) time.sleep(SLEEP) time.sleep(2) except KeyboardInterrupt: # Capture keyboard ^C to exit the program print('\nYou terminated the program. The program ends!') #pwm.clearAllPins() pwm.set_all_pwm(0, 0) pwm.close()