Skip to content

add LED-cycling to simpletest #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions examples/tlc5947_simpletest.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()