Skip to content

Commit edefe7e

Browse files
author
Melissa LeBlanc-Williams
committed
Added easy way to set pixels
1 parent 222014e commit edefe7e

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

adafruit_featherwing/dotstar_featherwing.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"
3333

3434
import board
35-
import time
3635
import adafruit_dotstar as dotstar
3736

3837
class DotStarFeatherWing:
@@ -46,10 +45,19 @@ def __init__(self, clock=board.D13, data=board.D11, brightness=0.2):
4645
:param pin data: The data pin for the featherwing
4746
:param float brightness: Optional brightness (0.0-1.0) that defaults to 1.0
4847
"""
49-
self._rows = 6
50-
self._columns = 12
48+
self.rows = 6
49+
self.columns = 12
5150
self._brightness = brightness
52-
self._dotstar = dotstar.DotStar(clock, data, self._rows * self._columns, brightness=self._brightness)
51+
self._dotstar = dotstar.DotStar(clock, data, self.rows * self.columns,
52+
brightness=self._brightness)
53+
54+
def __setitem__(self, indices, value):
55+
x, y = indices
56+
self._dotstar[y * self.columns + x] = value
57+
58+
def __getitem__(self, indices):
59+
x, y = indices
60+
return self._dotstar[y * self.columns + x]
5361

5462
def fill(self, color):
5563
"""Fills the wing with a color.
@@ -58,4 +66,3 @@ def fill(self, color):
5866
:param (int, int, int) color: the color to fill with
5967
"""
6068
self._dotstar.fill(color)
61-

examples/featherwing_dotstar_simpletest.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
"""This example changes the screen different colors"""
1+
"""
2+
This example changes the screen different colors
3+
and then draws random pixels at random locations
4+
"""
25

36
from time import sleep
47
import random
@@ -11,8 +14,14 @@
1114
def random_color():
1215
return random.randrange(0, 8) * 32
1316

17+
for i in range(0, 15):
18+
dotstar.fill((random_color(), random_color(), random_color()))
19+
sleep(.2)
20+
1421
# MAIN LOOP
1522
while True:
1623
# Fill screen with a random color
17-
dotstar.fill((random_color(), random_color(), random_color()))
18-
sleep(.25)
24+
x = random.randrange(0, dotstar.columns)
25+
y = random.randrange(0, dotstar.rows)
26+
dotstar[x, y] = (random_color(), random_color(), random_color())
27+
sleep(.1)

0 commit comments

Comments
 (0)