diff --git a/examples/tlc5947_simpletest.py b/examples/tlc5947_simpletest.py index 3ec915f..1205cd0 100644 --- a/examples/tlc5947_simpletest.py +++ b/examples/tlc5947_simpletest.py @@ -1,13 +1,13 @@ # Simple demo of controlling the TLC5947 12-bit 24-channel PWM controller. # Will update channel values to different PWM duty cycles. # Author: Tony DiCola + import board import busio import digitalio import adafruit_tlc5947 - # Define pins connected to the TLC5947 SCK = board.SCK MOSI = board.MOSI @@ -30,19 +30,36 @@ # it is used in your code. Change the duty_cycle property to a 16-bit value # (note this is NOT the 12-bit value supported by the chip natively) and the # PWM channel will be updated. -pwm0 = tlc5947.create_pwm_out(0) -# Set the channel 0 PWM to 50% (32767, or half of the max 65535): -pwm0.duty_cycle = 32767 +# With an RGB LED hooked up to pins 0, 1, and 2, cycle the red, green, and +# blue pins up and down: + +red = tlc5947.create_pwm_out(0) +green = tlc5947.create_pwm_out(1) +blue = tlc5947.create_pwm_out(2) + +step = 10 +start_pwm = 0 +end_pwm = 32767 # 50% (32767, or half of the maximum 65535): + +for pin in (red, green, blue): + # Brighten: + for pwm in range(start_pwm, end_pwm, step): + pin.duty_cycle = pwm + + # Dim: + for pwm in range(end_pwm, start_pwm, 0 - step): + pin.duty_cycle = pwm + # Note if auto_write was disabled you need to call write on the parent to # make sure the value is written (this is not common, if disabling auto_write # you probably want to use the direct 12-bit raw access instead shown below). -#tlc5947.write() +# tlc5947.write() # The other way to read and write channels is directly with each channel 12-bit # value and an item accessor syntax. Index into the TLC5947 with the channel # number (0-23) and get or set its 12-bit value (0-4095). # For example set channel 1 to 50% duty cycle. -tlc5947[1] = 2048 +# tlc5947[1] = 2048 # Again be sure to call write if you disabled auto_write. #tlc5947.write()