Skip to content

Commit 9bdeefd

Browse files
committed
Template code and FunHouse examples.
1 parent c0435e5 commit 9bdeefd

5 files changed

Lines changed: 126 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""CircuitPython Digital Input Example for FunHouse"""
2+
import board
3+
import digitalio
4+
5+
led = digitalio.DigitalInOut(board.LED)
6+
led.direction = digitalio.Direction.OUTPUT
7+
8+
button = digitalio.DigitalInOut(board.BUTTON_UP)
9+
button.switch_to_input(pull=digitalio.Pull.DOWN)
10+
11+
while True:
12+
if not button.value:
13+
led.value = False
14+
else:
15+
led.value = True

Adafruit_FunHouse/rainbow.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""CircuitPython DotStar rainbow example for FunHouse"""
2+
import time
3+
import board
4+
import adafruit_dotstar
5+
from _pixelbuf import colorwheel
6+
7+
dots = adafruit_dotstar.DotStar(board.DOTSTAR_CLOCK, board.DOTSTAR_DATA, 5, auto_write=False)
8+
dots.brightness = 0.3
9+
10+
11+
def rainbow(delay):
12+
for color_value in range(255):
13+
for pixels in range(5):
14+
pixel_index = (pixels * 256 // 5) + color_value
15+
dots[pixels] = colorwheel(pixel_index & 255)
16+
dots.show()
17+
time.sleep(delay)
18+
19+
20+
while True:
21+
rainbow(0.01)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""CircuitPython DotStar red, green, blue example for FunHouse"""
2+
import time
3+
import board
4+
import adafruit_dotstar
5+
6+
dots = adafruit_dotstar.DotStar(board.DOTSTAR_CLOCK, board.DOTSTAR_DATA, 5)
7+
dots.brightness = 0.3
8+
9+
while True:
10+
dots.fill((255, 0, 0))
11+
time.sleep(0.5)
12+
dots.fill((0, 255, 0))
13+
time.sleep(0.5)
14+
dots.fill((0, 0, 255))
15+
time.sleep(0.5)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
CircuitPython DotStar rainbow example - multiple DotStars.
3+
4+
This example is meant for boards that have multiple built-in DotStar LEDs.
5+
6+
** Update NUMBER_OF_PIXELS to the match the number of built-in DotStars on the board. It is found
7+
in THREE places in the code.
8+
9+
For example:
10+
If you are using a FunHouse, change NUMBER_OF_PIXELS to 5.
11+
12+
** Update PIXELBUF_VERSION to _pixelbuf if available for the board (this is the most common case!)
13+
or to adafruit_pypixelbuf where necessary (typically non-Express SAMD21 M0 boards).
14+
15+
For example:
16+
If you are using a FunHouse, change PIXELBUF_VERSION to _pixelbuf.
17+
If you are using a Trinket M0, change PIXELBUF_VERSION to adafruit_pypixelbuf.
18+
19+
** DO NOT INCLUDE THE pylint: disable LINE IN THE GUIDE CODE. It is present only to deal with the
20+
NUMBER_OF_PIXELS variable being undefined, and the dots setup line being too long with the variable
21+
in it in this pseudo-code. As you will be updating the variable in the guide, you will not need
22+
the pylint: disable.
23+
"""
24+
# pylint: disable=undefined-variable, line-too-long
25+
26+
import time
27+
import board
28+
import adafruit_dotstar
29+
from PIXELBUF_VERSION import colorwheel
30+
31+
dots = adafruit_dotstar.DotStar(board.DOTSTAR_CLOCK, board.DOTSTAR_DATA, NUMBER_OF_PIXELS, auto_write=False)
32+
dots.brightness = 0.3
33+
34+
35+
def rainbow(delay):
36+
for color_value in range(255):
37+
for pixels in range(NUMBER_OF_PIXELS):
38+
pixel_index = (pixels * 256 // NUMBER_OF_PIXELS) + color_value
39+
dots[pixels] = colorwheel(pixel_index & 255)
40+
dots.show()
41+
time.sleep(delay)
42+
43+
44+
while True:
45+
rainbow(0.01)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
CircuitPython DotStar red, green, blue, brightness control example - multiple DotStars.
3+
4+
This example is meant for boards that have multiple built-in DotStar LEDs.
5+
6+
Update NUMBER_OF_PIXELS to the match the number of built-in DotStars on the board.
7+
8+
DO NOT INCLUDE THE pylint: disable LINE IN THE GUIDE CODE. It is present only to deal with the
9+
NUMBER_OF_PIXELS variable being undefined in this pseudo-code. As you will be updating the variable
10+
in the guide, you will not need the pylint: disable.
11+
12+
For example:
13+
If you are using a FunHouse, change NUMBER_OF_PIXELS to 5.
14+
"""
15+
# pylint: disable=undefined-variable
16+
17+
import time
18+
import board
19+
import adafruit_dotstar
20+
21+
dots = adafruit_dotstar.DotStar(board.DOTSTAR_CLOCK, board.DOTSTAR_DATA, NUMBER_OF_PIXELS)
22+
dots.brightness = 0.3
23+
24+
while True:
25+
dots.fill((255, 0, 0))
26+
time.sleep(0.5)
27+
dots.fill((0, 255, 0))
28+
time.sleep(0.5)
29+
dots.fill((0, 0, 255))
30+
time.sleep(0.5)

0 commit comments

Comments
 (0)