Skip to content

Commit b9f3595

Browse files
authored
Merge pull request #95 from pimoroni/patch-lint-examples
Lint examples
2 parents 228a30b + a4600dc commit b9f3595

File tree

3 files changed

+33
-31
lines changed

3 files changed

+33
-31
lines changed

examples/anvil-colour-control.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,22 @@
2828
# Define functions that can be called from your Anvil app on the web
2929
anvil.server.connect(app.uplink_key)
3030

31+
3132
@anvil.server.callable
3233
def set_color(color_string):
3334
print("Setting LEDs to {}".format(color_string))
3435
c = Color(color_string)
35-
blinkt.set_all(c.red*255, c.green*255, c.blue*255, 1.0)
36+
blinkt.set_all(c.red * 255, c.green * 255, c.blue * 255, 1.0)
3637
blinkt.show()
3738

39+
3840
@anvil.server.callable
3941
def clear():
4042
print("Clearing LEDs")
4143
blinkt.clear()
4244
blinkt.show()
4345

46+
4447
# Display the URL where you can control the Blinkt LEDS
4548
print("Control your Blinkt LEDs at {}".format(app.origin))
4649
print("Press Ctrl-C to exit")

examples/eyedropper.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
#!/usr/bin/env python3
22

3-
from PIL import Image, ImageGrab
4-
import pyautogui, sys
5-
import blinkt
3+
from PIL import ImageGrab
4+
import pyautogui
5+
import blinkt
66
import time
77

88
print('Press Ctrl-C to quit.')
99

1010
try:
1111
while True:
1212
x, y = pyautogui.position()
13-
im = ImageGrab.grab(bbox =(x-1, y, x, y+1))
13+
im = ImageGrab.grab(bbox=(x - 1, y, x, y + 1))
1414
rawrgb = list(im.getdata())
15-
rgb = str(rawrgb)[2:-2]
16-
r, g, b = rgb.split(', ')
15+
rgb = str(rawrgb)[2:-2]
16+
r, g, b = rgb.split(', ')
1717
blinkt.set_all(r, g, b)
1818
blinkt.set_brightness(1)
1919
blinkt.show()
2020
time.sleep(0.01)
2121
except KeyboardInterrupt:
22-
print('\n')
22+
print('\n')

examples/kitt.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python
22

3-
from sys import exit # so the blinkt lights can turn off
43
import time # so we can wait between frames
54
import blinkt # so we can talk to our blinkt lights!
65

@@ -9,9 +8,9 @@
98
DECAY_FACTOR = 1.5 # how quickly should MAX_COLOUR fade? (1.5 works well)
109
TIME_SLEEP = 0.04 # seconds (0.04 works well)
1110

12-
PIXELS = blinkt.NUM_PIXELS # usually 8, can use fewer if you like!
11+
PIXELS = blinkt.NUM_PIXELS # usually 8, can use fewer if you like!
1312

14-
blinkt.clear # make all pixels blank / black
13+
blinkt.clear # make all pixels blank / black
1514
blinkt.set_brightness(BRIGHTNESS)
1615

1716
brightpixel = -1
@@ -20,23 +19,23 @@
2019
print('Hello Michael.\nHow are you today?')
2120

2221
while True:
23-
# decay all pixels
24-
for x in range(PIXELS):
25-
pixel = blinkt.get_pixel(x) # format is [ r, g, b, brightness? ]
26-
blinkt.set_pixel(x, pixel[0] / DECAY_FACTOR, 0, 0)
27-
28-
# brightpixel should move back and forth all the pixels,
29-
# in a ping-pong, triangle wave. Not (co)sine.
30-
brightpixel += direction
31-
32-
if brightpixel >= PIXELS - 1:
33-
brightpixel = PIXELS - 1
34-
direction = - abs(direction)
35-
if brightpixel <= 0:
36-
brightpixel = 0
37-
direction = abs(direction)
38-
39-
blinkt.set_pixel(brightpixel, MAX_COLOUR, 0, 0)
40-
41-
blinkt.show() # draw the lights!
42-
time.sleep(TIME_SLEEP) # wait a bit before working on next frame
22+
# decay all pixels
23+
for x in range(PIXELS):
24+
pixel = blinkt.get_pixel(x) # format is [ r, g, b, brightness? ]
25+
blinkt.set_pixel(x, pixel[0] / DECAY_FACTOR, 0, 0)
26+
27+
# brightpixel should move back and forth all the pixels,
28+
# in a ping-pong, triangle wave. Not (co)sine.
29+
brightpixel += direction
30+
31+
if brightpixel >= PIXELS - 1:
32+
brightpixel = PIXELS - 1
33+
direction = - abs(direction)
34+
if brightpixel <= 0:
35+
brightpixel = 0
36+
direction = abs(direction)
37+
38+
blinkt.set_pixel(brightpixel, MAX_COLOUR, 0, 0)
39+
40+
blinkt.show() # draw the lights!
41+
time.sleep(TIME_SLEEP) # wait a bit before working on next frame

0 commit comments

Comments
 (0)