Skip to content

Commit 2f171f5

Browse files
committed
Shakeup examples and fix README links.
1 parent 8134ffa commit 2f171f5

28 files changed

+154
-209
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![Blinkt!](blinkt-logo.png)
22

3-
[![Build Status](https://travis-ci.com/pimoroni/blinkt.svg?branch=master)](https://travis-ci.com/pimoroni/blinkt)
3+
[![Build Status](https://img.shields.io/github/actions/workflow/status/pimoroni/blinkt/test.yml?branch=main)](https://github.com/pimoroni/blinkt/actions/workflows/test.yml)
44
[![Coverage Status](https://coveralls.io/repos/github/pimoroni/blinkt/badge.svg?branch=master)](https://coveralls.io/github/pimoroni/blinkt?branch=master)
55
[![PyPi Package](https://img.shields.io/pypi/v/blinkt.svg)](https://pypi.python.org/pypi/blinkt)
66
[![Python Versions](https://img.shields.io/pypi/pyversions/blinkt.svg)](https://pypi.python.org/pypi/blinkt)

examples/1d_tetris.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,5 @@ def main():
9090
update()
9191

9292

93-
if __name__ == '__main__':
93+
if __name__ == "__main__":
9494
main()

examples/anvil-colour-control.py renamed to examples/anvil_colour_control.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
@anvil.server.callable
3333
def set_color(color_string):
34-
print("Setting LEDs to {}".format(color_string))
34+
print(f"Setting LEDs to {color_string}")
3535
c = Color(color_string)
3636
blinkt.set_all(c.red * 255, c.green * 255, c.blue * 255, 1.0)
3737
blinkt.show()
@@ -45,7 +45,7 @@ def clear():
4545

4646

4747
# Display the URL where you can control the Blinkt LEDS
48-
print("Control your Blinkt LEDs at {}".format(app.origin))
48+
print(f"Control your Blinkt LEDs at {app.origin}")
4949
print("Press Ctrl-C to exit")
5050

5151
# Keep the script running until the user exits with Ctrl-C

examples/binary_clock.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
MODE_HOUR = 0
1010
MODE_MIN = 1
1111
MODE_SEC = 2
12-
MODE_NAMES = {MODE_HOUR: 'Hour mode',
13-
MODE_MIN: 'Minute mode',
14-
MODE_SEC: 'Seconds mode'}
12+
MODE_NAMES = {MODE_HOUR: "Hour mode", MODE_MIN: "Minute mode", MODE_SEC: "Seconds mode"}
1513

1614
time_to_stay_in_mode = 3
1715
time_in_mode = 0
@@ -62,11 +60,7 @@
6260
blinkt.set_pixel(7 - x, r, g, b)
6361

6462
blinkt.show()
65-
print('{h:2d}:{m:02d}:{s:02d}; mode: {mode}; time in mode: {tim}'.format(h=h,
66-
m=m,
67-
s=s,
68-
mode=MODE_NAMES[mode],
69-
tim=time_in_mode))
63+
print(f"{h:2d}:{m:02d}:{s:02d}; mode: {MODE_NAMES[mode]}; time in mode: {time_in_mode}")
7064

7165
time_in_mode += 1
7266
if time_in_mode == time_to_stay_in_mode:

examples/binary_clock_meld.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import blinkt
66

7-
print('Hour = Red, Minute = Green, Second = Blue')
7+
print("Hour = Red, Minute = Green, Second = Blue")
88

99
blinkt.set_clear_on_exit()
1010

@@ -16,7 +16,7 @@
1616
t = localtime()
1717
h, m, s = t.tm_hour, t.tm_min, t.tm_sec
1818

19-
print('{h:2d}:{m:02d}:{s:02d}'.format(h=h, m=m, s=s))
19+
print(f"{h:2d}:{m:02d}:{s:02d}")
2020

2121
blinkt.clear()
2222

examples/blinkt_thermo.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,35 @@
33
# Data from OpenWeatherMap
44
# show_graph function adapted from cpu_temp.py
55

6-
from sys import exit
76
from time import sleep
87

98
try:
109
import requests
1110
except ImportError:
12-
exit('This script requires the requests module\nInstall with: sudo pip install requests')
11+
raise ImportError("This script requires the requests module\nInstall with: python3 -m pip install requests")
1312

1413
import blinkt
1514

1615
# Grab your API key here: http://openweathermap.org
1716
# List of city ID city.list.json.gz can be downloaded here http://bulk.openweathermap.org/sample/
18-
API_KEY = ''
19-
CITY_ID = ''
17+
API_KEY = ""
18+
CITY_ID = ""
2019

21-
url = 'http://api.openweathermap.org/data/2.5/weather'
20+
url = "http://api.openweathermap.org/data/2.5/weather"
2221

2322
temp = 0
2423

2524

2625
def update_weather():
2726
global temp
28-
payload = {
29-
'id': CITY_ID,
30-
'units': 'metric',
31-
'appid': API_KEY
32-
}
27+
payload = {"id": CITY_ID, "units": "metric", "appid": API_KEY}
3328
try:
3429
r = requests.get(url=url, params=payload)
35-
temp = r.json().get('main').get('temp')
36-
print('Temperture = ' + str(temp) + ' C')
30+
temp = r.json().get("main").get("temp")
31+
print("Temperture = " + str(temp) + " C")
3732

3833
except requests.exceptions.ConnectionError:
39-
print('Connection Error')
34+
print("Connection Error")
4035

4136

4237
def show_graph(v, r, g, b):
@@ -54,7 +49,7 @@ def show_graph(v, r, g, b):
5449
def draw_thermo(temp):
5550
v = temp
5651
v /= 40
57-
v += (1 / 8)
52+
v += 1 / 8
5853
show_graph(v, 255, 0, 0)
5954

6055

examples/candle.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
import colorsys
44
import time
5-
from sys import exit
65

76
try:
87
import numpy as np
98
except ImportError:
10-
exit('This script requires the numpy module\nInstall with: python3 -m pip install numpy')
9+
raise ImportError("This script requires the numpy module\nInstall with: python3 -m pip install numpy")
1110

1211
import blinkt
1312

examples/cheerlights.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
try:
66
import requests
77
except ImportError:
8-
exit('This script requires the requests module\nInstall with: sudo pip install requests')
8+
exit("This script requires the requests module\nInstall with: python3 -m pip install requests")
99

1010
import blinkt
1111

@@ -14,20 +14,20 @@
1414

1515
def hex_to_rgb(col_hex):
1616
"""Convert a hex colour to an RGB tuple."""
17-
col_hex = col_hex.lstrip('#')
17+
col_hex = col_hex.lstrip("#")
1818
return bytearray.fromhex(col_hex)
1919

2020

2121
while True:
22-
r = requests.get('http://api.thingspeak.com/channels/1417/field/2/last.json', timeout=2)
22+
r = requests.get("http://api.thingspeak.com/channels/1417/field/2/last.json", timeout=2)
2323
json = r.json()
2424

25-
if 'field2' not in json:
26-
print('Error {status}: {error}'.format(status=json['status'], error=json['error']))
25+
if "field2" not in json:
26+
print(f"Error {json['status']}: {json['error']}")
2727
time.sleep(5)
2828
continue
2929

30-
r, g, b = hex_to_rgb(json['field2'])
30+
r, g, b = hex_to_rgb(json["field2"])
3131

3232
for i in range(blinkt.NUM_PIXELS):
3333
blinkt.set_pixel(i, r, g, b)

examples/cpu_load.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/usr/bin/env python
22
import time
3-
from sys import exit
43

54
try:
65
import psutil
76
except ImportError:
8-
exit('This script requires the psutil module\nInstall with: sudo apt install python3-psutil')
7+
raise ImportError("This script requires the psutil module\nInstall with: sudo apt install python3-psutil")
98

109
import blinkt
1110

examples/cpu_temp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010

1111
def get_cpu_temperature():
12-
process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE)
12+
process = Popen(["vcgencmd", "measure_temp"], stdout=PIPE)
1313
output, _error = process.communicate()
1414
output = output.decode()
1515

16-
pos_start = output.index('=') + 1
16+
pos_start = output.index("=") + 1
1717
pos_end = output.rindex("'")
1818

1919
temp = float(output[pos_start:pos_end])

0 commit comments

Comments
 (0)