Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d438222
Showing
61 changed files
with
2,689 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
__pycache__/ | ||
sphinx/_build/ | ||
*.py[cod] | ||
*.swp | ||
dist/ | ||
sdist/ | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
eggs/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
*.deb | ||
*.dsc | ||
*.build | ||
*.changes | ||
*.orig.* | ||
testing/ | ||
MANIFEST | ||
.idea | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
library/test/scrollphat/ | ||
library/debian/ | ||
packaging/*tar.xz | ||
.DS_Store | ||
sphinx.virtualenv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 Pimoroni Ltd. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
![LED SHIM](led-shim-logo.png) | ||
https://shop.pimoroni.com/products/led-shim | ||
|
||
17x7 pixels of single-colour, brightness-controlled, message scrolling goodness! | ||
|
||
## Installing | ||
|
||
### Full install (recommended): | ||
|
||
We've created an easy installation script that will install all pre-requisites and get your LED SHIM | ||
up and running with minimal efforts. To run it, fire up Terminal which you'll find in Menu -> Accessories -> Terminal | ||
on your Raspberry Pi desktop, as illustrated below: | ||
|
||
![Finding the terminal](http://get.pimoroni.com/resources/github-repo-terminal.png) | ||
|
||
In the new terminal window type the command exactly as it appears below (check for typos) and follow the on-screen instructions: | ||
|
||
```bash | ||
curl https://get.pimoroni.com/ledshim | bash | ||
``` | ||
|
||
Alternatively, on Raspbian, you can download the `pimoroni-dashboard` and install your product by browsing to the relevant entry: | ||
|
||
```bash | ||
sudo apt-get install pimoroni | ||
``` | ||
(you will find the Dashboard under 'Accessories' too, in the Pi menu - or just run `pimoroni-dashboard` at the command line) | ||
|
||
If you choose to download examples you'll find them in `/home/pi/Pimoroni/ledshim/`. | ||
|
||
### Manual install: | ||
|
||
#### Library install for Python 3: | ||
|
||
on Raspbian: | ||
|
||
```bash | ||
sudo apt-get install python3-ledshim | ||
``` | ||
|
||
other environments: | ||
|
||
```bash | ||
sudo pip3 install ledshim | ||
``` | ||
|
||
#### Library install for Python 2: | ||
|
||
on Raspbian: | ||
|
||
```bash | ||
sudo apt-get install python-ledshim | ||
``` | ||
|
||
other environments: | ||
|
||
```bash | ||
sudo pip2 install ledshim | ||
``` | ||
|
||
### Development: | ||
|
||
If you want to contribute, or like living on the edge of your seat by having the latest code, you should clone this repository, `cd` to the library directory, and run: | ||
|
||
```bash | ||
sudo python3 setup.py install | ||
``` | ||
(or `sudo python setup.py install` whichever your primary Python environment may be) | ||
|
||
In all cases you will have to enable the i2c bus. | ||
|
||
## Documentation & Support | ||
|
||
* Guides and tutorials - https://learn.pimoroni.com/led-shim | ||
* Function reference - http://docs.pimoroni.com/ledshim/ | ||
* GPIO Pinout - https://pinout.xyz/pinout/led_shim | ||
* Get help - http://forums.pimoroni.com/c/support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env python | ||
|
||
import time | ||
from random import randint | ||
|
||
import ledshim | ||
|
||
MAX_SIZE = 4 | ||
MAX_GRID = ledshim.NUM_PIXELS + MAX_SIZE - 1 | ||
|
||
OFF = (0, 0, 0) | ||
grid = [OFF] * (MAX_GRID + 1) | ||
|
||
ledshim.set_clear_on_exit() | ||
|
||
# The tetris algorithm fail when random_color was 0,0,0 now avoided | ||
def random_color(): | ||
return (randint(0, 255), randint(0, 255), randint(1, 50)) | ||
|
||
def random_tile(max_size, min_size=1): | ||
return (randint(min_size, max_size), random_color()) | ||
|
||
def place(tile): | ||
for i in range(0, tile[0]): | ||
grid[MAX_GRID - i - len(tile)] = tile[1] | ||
|
||
def update(): | ||
for i in range(ledshim.NUM_PIXELS): | ||
ledshim.set_pixel(i, grid[i][0], grid[i][1], grid[i][2]) | ||
ledshim.show() | ||
|
||
def has_lines(): | ||
return grid[0] != OFF | ||
|
||
def get_lines(): | ||
lines = [] | ||
for i, color in enumerate(grid): | ||
if color == OFF: | ||
return lines | ||
else: | ||
lines.append(i) | ||
return lines | ||
|
||
def blink_lines(): | ||
def hide(): | ||
for line in get_lines(): | ||
ledshim.set_pixel(line, 0, 0, 0) | ||
ledshim.show() | ||
|
||
hide() | ||
time.sleep(0.5) | ||
update() | ||
time.sleep(0.5) | ||
hide() | ||
time.sleep(0.5) | ||
|
||
def remove_lines(): | ||
for line in get_lines(): | ||
grid[line] = OFF | ||
|
||
def gravity(): | ||
grid.append(OFF) | ||
grid.pop(0) | ||
|
||
def main(): | ||
ledshim.set_brightness(0.6) | ||
place(random_tile(MAX_SIZE)) | ||
update() | ||
|
||
while True: | ||
time.sleep(0.5) | ||
|
||
if has_lines(): | ||
blink_lines() | ||
remove_lines() | ||
place(random_tile(MAX_SIZE)) | ||
else: | ||
gravity() | ||
|
||
update() | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## Examples | ||
|
||
The examples in this directory should just work with LED SHIM, although you'll need to add Twitter developer access tokens and secrets in the `twitter_monitor.py` example. You can get these at [https://dev.twitter.com/](https://dev.twitter.com/), after setting up a new application. | ||
|
||
The examples in the `extra_examples` folder are designed to work with other pHATs and HATs, so be aware of that before trying them. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python | ||
|
||
import time | ||
|
||
import ledshim | ||
|
||
r, g, b = 255, 0, 0 | ||
|
||
delay = 0.1 | ||
|
||
half_way = ledshim.NUM_PIXELS / 2 | ||
|
||
while True: | ||
# Turn pixels on | ||
for x in range(half_way): | ||
ledshim.set_pixel(half_way-1-x, r, g, b) | ||
ledshim.set_pixel(half_way+x, r, g, b) | ||
ledshim.show() | ||
time.sleep(delay) | ||
|
||
# Turn pixels off | ||
for x in range(half_way): | ||
ledshim.set_pixel(x, 0, 0, 0) | ||
ledshim.set_pixel(ledshim.NUM_PIXELS-1-x, 0, 0, 0) | ||
ledshim.show() | ||
time.sleep(delay) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python | ||
|
||
#Data from OpenWeatherMap | ||
#show_graph function adapted from cpu_temp.py | ||
|
||
from time import sleep | ||
from sys import exit | ||
|
||
try: | ||
import requests | ||
except ImportError: | ||
exit("This script requires the requests module\nInstall with: sudo pip install requests") | ||
|
||
import ledshim | ||
|
||
|
||
#Grab your API key here: http://openweathermap.org | ||
#List of city ID city.list.json.gz can be downloaded here http://bulk.openweathermap.org/sample/ | ||
API_KEY='' | ||
CITY_ID='' | ||
|
||
url = 'http://api.openweathermap.org/data/2.5/weather' | ||
|
||
temp = 0 | ||
|
||
def update_weather(): | ||
payload = { | ||
'id': CITY_ID, | ||
'units': 'metric', | ||
'appid': API_KEY | ||
} | ||
global temp | ||
try: | ||
r = requests.get(url=url, params=payload) | ||
temp = r.json().get('main').get('temp') | ||
print("Temperture = "+str(temp)+" C") | ||
except: | ||
print("Connection Error") | ||
|
||
def show_graph(v, r, g, b): | ||
v *= ledshim.NUM_PIXELS | ||
for x in range(ledshim.NUM_PIXELS): | ||
if v < 0: | ||
r, g, b = 0, 0, 0 | ||
else: | ||
r, g, b = [int(min(v, 1.0) * c) for c in [r, g, b]] | ||
ledshim.set_pixel(x, r, g, b) | ||
v -= 1 | ||
ledshim.show() | ||
|
||
def draw_thermo(temp): | ||
v = temp | ||
v /= 40 | ||
v += (1/8) | ||
show_graph(v, 255, 0, 0) | ||
|
||
ledshim.set_brightness(0.1) | ||
|
||
while 1: | ||
update_weather() | ||
draw_thermo(temp) | ||
sleep(120) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python | ||
|
||
import colorsys | ||
import time | ||
from sys import exit | ||
|
||
try: | ||
import numpy as np | ||
except ImportError: | ||
exit("This script requires the numpy module\nInstall with: sudo pip install numpy") | ||
|
||
import ledshim | ||
|
||
|
||
ledshim.clear() | ||
start = 0 | ||
end = 60 | ||
|
||
while True: | ||
wait = np.random.choice(np.random.noncentral_chisquare(ledshim.NUM_PIXELS / 2, 1, 1000), 1)[0] / 50 | ||
n = np.random.choice(np.random.noncentral_chisquare(ledshim.NUM_PIXELS / 2, 0.1, 1000), 1) | ||
limit = int(n[0]) | ||
|
||
if limit > ledshim.NUM_PIXELS: | ||
limit = ledshim.NUM_PIXELS | ||
|
||
for pixel in range(limit): | ||
hue = start + (((end - start) / float(ledshim.NUM_PIXELS)) * pixel) | ||
r, g, b = [int(c * 255) for c in colorsys.hsv_to_rgb(hue/360.0, 1.0, 1.0)] | ||
ledshim.set_pixel(pixel, r, g, b) | ||
ledshim.show() | ||
time.sleep(0.05 / (pixel + 1)) | ||
|
||
time.sleep(wait) | ||
ledshim.clear() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python | ||
|
||
import time | ||
from sys import exit | ||
|
||
try: | ||
import requests | ||
except ImportError: | ||
exit("This script requires the requests module\nInstall with: sudo pip install requests") | ||
|
||
import ledshim | ||
|
||
ledshim.set_clear_on_exit() | ||
|
||
def hex_to_rgb(col_hex): | ||
"""Convert a hex colour to an RGB tuple""" | ||
col_hex = col_hex.lstrip("#") | ||
return bytearray.fromhex(col_hex) | ||
|
||
while True: | ||
r = requests.get("http://api.thingspeak.com/channels/1417/field/2/last.json", timeout=2) | ||
r, g, b = hex_to_rgb(r.json()["field2"]) | ||
|
||
for i in range(ledshim.NUM_PIXELS): | ||
ledshim.set_pixel(i, r, g, b) | ||
|
||
ledshim.show() | ||
|
||
time.sleep(5) # Be friendly to the API |
Oops, something went wrong.