1# !/usr/bin/env python
2# ---------------------------------------------------------------------------------
3# qwiic_led_stick_ex9_change_length.py
4#
5# This example changes the length of the attached LED strip and shows the results
6# by writing the whole strip white. Length will not reset on restart, change back
7# to 10 if necessary with my_stick.change_length(10);
8# If you add LEDs to the end of the sitck, you must change the length to be able to
9# use them.
10# --------------------------------------------------------------------------------
11#
12# Written by Priyanka Makin @ SparkFun Electronics, June 2021
13#
14# This python library supports the SpakrFun Electronics qwiic sensor/
15# board ecosystem on a Raspberry Pi (and compatible) board computers.
16#
17# More information on qwiic is at https://www.sparkfun.com/qwiic
18#
19# Do you like this library? Help support SparkFun by buying a board!
20#
21#==================================================================================
22# Copyright (c) 2019 SparkFun Electronics
23#
24# Permission is hereby granted, free of charge, to any person obtaining a copy
25# of this software and associated documentation files (the "Software"), to deal
26# in the Software without restriction, including without limitation the rights
27# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28# copies of the Software, and to permit persons to whom the Software is
29# furnished to do so, subject to the following conditions:
30#
31# The above copyright notice and this permission notice shall be included in all
32# copies or substantial portions of the Software.
33#
34# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40# SOFTWARE.
41#==================================================================================
42# Example 9
43
44from __future__ import print_function
45import qwiic_led_stick
46import time
47import sys
48
49def run_example():
50
51 print("\nSparkFun Qwiic LED Stick Example 9")
52 my_stick = qwiic_led_stick.QwiicLEDStick()
53
54 if my_stick.begin() == False:
55 print("\nThe Qwiic LED Stick isn't connected to the system. Please check your connection", \
56 file=sys.stderr)
57 return
58 print("\nLED Stick ready!")
59
60 # First, turn all LEDs off
61 my_stick.LED_off()
62 # Give stick time to turn all LEDs off
63 time.sleep(0.5)
64
65 # Change LED length to 5
66 # This will allow you to write to a maximum of 5 LEDs
67 my_stick.change_length(5)
68 # Set all LEDs to dim white, notice only 5 are lit.
69 my_stick.set_all_LED_color(10, 10, 10)
70
71if __name__ == '__main__':
72 try:
73 run_example()
74 except (KeyboardInterrupt, SystemExit) as exErr:
75 print("\nEnding Example 1")
76 sys.exit(0)