|
1 | 1 | # Simple demo of controlling the TLC5947 12-bit 24-channel PWM controller.
|
2 | 2 | # Will update channel values to different PWM duty cycles.
|
3 | 3 | # Author: Tony DiCola
|
| 4 | + |
4 | 5 | import board
|
5 | 6 | import busio
|
6 | 7 | import digitalio
|
7 | 8 |
|
8 | 9 | import adafruit_tlc5947
|
9 | 10 |
|
10 |
| - |
11 | 11 | # Define pins connected to the TLC5947
|
12 | 12 | SCK = board.SCK
|
13 | 13 | MOSI = board.MOSI
|
|
30 | 30 | # it is used in your code. Change the duty_cycle property to a 16-bit value
|
31 | 31 | # (note this is NOT the 12-bit value supported by the chip natively) and the
|
32 | 32 | # PWM channel will be updated.
|
33 |
| -pwm0 = tlc5947.create_pwm_out(0) |
34 | 33 |
|
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 | + |
37 | 54 | # Note if auto_write was disabled you need to call write on the parent to
|
38 | 55 | # make sure the value is written (this is not common, if disabling auto_write
|
39 | 56 | # you probably want to use the direct 12-bit raw access instead shown below).
|
40 |
| -#tlc5947.write() |
| 57 | +# tlc5947.write() |
41 | 58 |
|
42 | 59 | # The other way to read and write channels is directly with each channel 12-bit
|
43 | 60 | # value and an item accessor syntax. Index into the TLC5947 with the channel
|
44 | 61 | # number (0-23) and get or set its 12-bit value (0-4095).
|
45 | 62 | # For example set channel 1 to 50% duty cycle.
|
46 |
| -tlc5947[1] = 2048 |
| 63 | +# tlc5947[1] = 2048 |
47 | 64 | # Again be sure to call write if you disabled auto_write.
|
48 | 65 | #tlc5947.write()
|
0 commit comments