Skip to content

Commit 48d45c6

Browse files
author
Brennen Bearnes
committed
add LED-cycling to simpletest
1 parent 8428cfe commit 48d45c6

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

examples/tlc5947_simpletest.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Simple demo of controlling the TLC5947 12-bit 24-channel PWM controller.
22
# Will update channel values to different PWM duty cycles.
33
# Author: Tony DiCola
4+
45
import board
56
import busio
67
import digitalio
78

89
import adafruit_tlc5947
910

10-
1111
# Define pins connected to the TLC5947
1212
SCK = board.SCK
1313
MOSI = board.MOSI
@@ -30,19 +30,36 @@
3030
# it is used in your code. Change the duty_cycle property to a 16-bit value
3131
# (note this is NOT the 12-bit value supported by the chip natively) and the
3232
# PWM channel will be updated.
33-
pwm0 = tlc5947.create_pwm_out(0)
3433

35-
# Set the channel 0 PWM to 50% (32767, or half of the max 65535):
36-
pwm0.duty_cycle = 32767
34+
# With an RGB LED hooked up to pins 0, 1, and 2, cycle the red, green, and
35+
# blue pins up and down:
36+
37+
red = tlc5947.create_pwm_out(0)
38+
green = tlc5947.create_pwm_out(1)
39+
blue = tlc5947.create_pwm_out(2)
40+
41+
step = 10
42+
start_pwm = 0
43+
end_pwm = 32767 # 50% (32767, or half of the maximum 65535):
44+
45+
for pin in (red, green, blue):
46+
# Brighten:
47+
for pwm in range(start_pwm, end_pwm, step):
48+
pin.duty_cycle = pwm
49+
50+
# Dim:
51+
for pwm in range(end_pwm, start_pwm, 0 - step):
52+
pin.duty_cycle = pwm
53+
3754
# Note if auto_write was disabled you need to call write on the parent to
3855
# make sure the value is written (this is not common, if disabling auto_write
3956
# you probably want to use the direct 12-bit raw access instead shown below).
40-
#tlc5947.write()
57+
# tlc5947.write()
4158

4259
# The other way to read and write channels is directly with each channel 12-bit
4360
# value and an item accessor syntax. Index into the TLC5947 with the channel
4461
# number (0-23) and get or set its 12-bit value (0-4095).
4562
# For example set channel 1 to 50% duty cycle.
46-
tlc5947[1] = 2048
63+
# tlc5947[1] = 2048
4764
# Again be sure to call write if you disabled auto_write.
4865
#tlc5947.write()

0 commit comments

Comments
 (0)