Skip to content

Commit 1610cd6

Browse files
authored
Merge pull request #21 from druck13/neopixel-blinkt
Added neopixel-blinkt library
2 parents 7a81e90 + ab2356f commit 1610cd6

File tree

8 files changed

+206
-0
lines changed

8 files changed

+206
-0
lines changed

neopixel-blinkt/CHANGELOG.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
0.0.1
2+
-----
3+
4+
* Initial Revision
5+

neopixel-blinkt/LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Pimoroni Ltd
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

neopixel-blinkt/MANIFEST.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include CHANGELOG.txt
2+
include LICENSE.txt
3+
include README.rst
4+
include setup.py
5+
include blinkt.py

neopixel-blinkt/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#Blinkt with Pan-Tilt HAT and Neopixel Library

neopixel-blinkt/README.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.. figure:: blinkt-logo.png
2+
:alt: Blinkt!
3+
4+
Blinkt compatibility for a Pan-Tilt HAT and an Adafruit Neopixel!
5+
6+
7+
https://shop.pimoroni.com/products/blinkt
8+
https://shop.pimoroni.com/products/pan-tilt-hat
9+
https://shop.pimoroni.com/products/neopixel-stick-8-x-5050-rgbw-leds
10+
11+
Run programs designed for the Blinkt! on a Pan-Tilt HAT with an Adafruit Neopixel strip
12+
13+
14+
Installing
15+
----------
16+
17+
Manual install Python 2:
18+
~~~~~~~~~~~~~~~~~~~~~~~~
19+
20+
``cd`` to the library directory, and run:
21+
22+
.. code:: bash
23+
24+
sudo python setup.py install
25+
26+
Manual install Python 3:
27+
~~~~~~~~~~~~~~~~~~~~~~~~
28+
29+
``cd`` to the library directory, and run:
30+
31+
.. code:: bash
32+
33+
sudo python3 setup.py install
34+
35+
36+
Documentation & Support
37+
-----------------------
38+
39+
- Blinkt! - https://learn.pimoroni.com/blinkt
40+
- Pan-Tilt HAT - https://learn.pimoroni.com/pan-tilt-hat
41+
- Neop Pixel - https://learn.adafruit.com/adafruit-neopixel-uberguide
42+

neopixel-blinkt/blinkt.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""Library for Pimoroni Blinkt! programs compatibility with a Pimoroni Pan-Tilt HAT and an Adafruit Neopixel strip"""
2+
import sys
3+
import pantilthat
4+
import atexit
5+
import signal
6+
7+
_clear_on_exit = True
8+
_brightness = 0.2
9+
NUM_PIXELS = 8
10+
11+
def _exit():
12+
if _clear_on_exit:
13+
clear()
14+
show()
15+
16+
17+
def set_brightness(brightness):
18+
"""Set the brightness of all pixels
19+
20+
:param brightness: Brightness: 0.0 to 1.0
21+
"""
22+
23+
if brightness < 0 or brightness > 1:
24+
raise ValueError("Brightness should be between 0.0 and 1.0")
25+
26+
global _brightness
27+
_brightness = brightness
28+
29+
30+
def clear():
31+
pantilthat.clear()
32+
33+
34+
def show():
35+
pantilthat.show()
36+
37+
38+
def set_all(r, g, b, brightness=None):
39+
global _brightness
40+
if brightness is not None:
41+
_brightness = brightness
42+
pantilthat.set_all(int(r*_brightness), int(g*_brightness), int(b*_brightness))
43+
44+
45+
def set_pixel(x, r, g, b, brightness=None):
46+
global _brightness
47+
if brightness is not None:
48+
_brightness = brightness
49+
pantilthat.set_pixel(x, int(r*_brightness), int(g*_brightness), int(b*_brightness))
50+
51+
52+
def set_clear_on_exit(value=True):
53+
"""Set whether Blinkt! should be cleared upon exit
54+
55+
By default Blinkt! will turn off the pixels on exit, but calling::
56+
57+
blinkt.set_clear_on_exit(False)
58+
59+
Will ensure that it does not.
60+
61+
:param value: True or False (default True)
62+
"""
63+
global _clear_on_exit
64+
_clear_on_exit = value
65+
66+
67+
def interrupt_handler(signum, frame):
68+
print("\rKeyboardInterrupt")
69+
sys.exit(128+signum)
70+
71+
72+
# Module Initialisation
73+
pantilthat.light_mode(pantilthat.WS2812)
74+
pantilthat.light_type(pantilthat.GRBW)
75+
atexit.register(_exit)
76+
signal.signal(signal.SIGINT, interrupt_handler)

neopixel-blinkt/setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
exclude =
3+
.git,
4+
__pycache__

neopixel-blinkt/setup.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
Copyright (c) 2016 Pimoroni.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy of
7+
this software and associated documentation files (the "Software"), to deal in
8+
the Software without restriction, including without limitation the rights to
9+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10+
of the Software, and to permit persons to whom the Software is furnished to do
11+
so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
"""
24+
25+
try:
26+
from setuptools import setup
27+
except ImportError:
28+
from distutils.core import setup
29+
30+
classifiers = ['Development Status :: 5 - Production/Stable',
31+
'Operating System :: POSIX :: Linux',
32+
'License :: OSI Approved :: MIT License',
33+
'Intended Audience :: Developers',
34+
'Programming Language :: Python :: 2.7',
35+
'Programming Language :: Python :: 3',
36+
'Topic :: Software Development',
37+
'Topic :: System :: Hardware']
38+
39+
setup(
40+
name='neopixel-blinkt',
41+
version='0.0.1',
42+
author='David Ruck',
43+
author_email='pimoroni@druck.org.uk',
44+
description="""Python library to allow Pimoroni Blinkt! programs to run with a Pimoroni Pan-Tilt HAT and an Adafruit Neopixel strip""",
45+
long_description=open('README.rst').read() + '\n' + open('CHANGELOG.txt').read(),
46+
license='MIT',
47+
keywords='Raspberry Pi Neopixel',
48+
url='http://www.pimoroni.com',
49+
classifiers=classifiers,
50+
py_modules=['blinkt'],
51+
install_requires=['pantilthat']
52+
)

0 commit comments

Comments
 (0)