Simple tests¶
Ensure your device works with this simple test.
1 2 3 4 5 6 7 8 9 10 11 12 13 | """ Example to print out the voltage and current using the INA219 """
import time
from adafruit_featherwing import ina219_featherwing
INA219 = ina219_featherwing.INA219FeatherWing()
while True:
print("Bus Voltage: {} V".format(INA219.bus_voltage))
print("Shunt Voltage: {} V".format(INA219.shunt_voltage))
print("Voltage: {} V".format(INA219.voltage))
print("Current: {} mA".format(INA219.current))
print("")
time.sleep(0.5)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | """This example zeros the joystick, and prints when the joystick moves
or the buttons are pressed."""
import time
from adafruit_featherwing import joy_featherwing
wing = joy_featherwing.JoyFeatherWing()
last_x = 0
last_y = 0
while True:
x, y = wing.joystick
if (abs(x - last_x) > 3) or (abs(y - last_y) > 3):
last_x = x
last_y = y
print(x, y)
if wing.button_a:
print("Button A!")
if wing.button_b:
print("Button B!")
if wing.button_x:
print("Button X!")
if wing.button_y:
print("Button Y!")
if wing.button_select:
print("Button SELECT!")
time.sleep(.01)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | """This example changes the fill, brightness, blink rates,
shows number and text printing, displays a counter
and then shows off the new marquee features."""
from time import sleep
from adafruit_featherwing import alphanum_featherwing
display = alphanum_featherwing.AlphaNumFeatherWing()
#Fill and empty all segments
for count in range(0, 3):
display.fill(True)
sleep(0.5)
display.fill(False)
sleep(0.5)
#Display a number and text
display.print(1234)
sleep(1)
display.print('Text')
#Change brightness
for brightness in range(0, 16):
display.brightness = brightness
sleep(0.1)
#Change blink rate
for blink_rate in range(3, 0, -1):
display.blink_rate = blink_rate
sleep(4)
display.blink_rate = 0
#Show a counter using decimals
count = 975.0
while count < 1025:
count += 1
display.print(count)
sleep(0.1)
#Show the Marquee
display.marquee('This is a really long message!!! ', 0.2)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | """
This plays various animations
and then draws random pixels at random locations
"""
from time import sleep
import random
from adafruit_featherwing import dotstar_featherwing
dotstar = dotstar_featherwing.DotStarFeatherWing()
# HELPERS
# a random color 0 -> 224
def random_color():
return random.randrange(0, 8) * 32
# Fill screen with random colors at random brightnesses
for i in range(0, 5):
dotstar.fill((random_color(), random_color(), random_color()))
dotstar.brightness = random.randrange(2, 10) / 10
sleep(.2)
# Set display to 30% brightness
dotstar.brightness = 0.3
# Create a gradiant drawing each pixel
for x in range(0, dotstar.columns):
for y in range(dotstar.rows - 1, -1, -1):
dotstar[x, y] = (y * 42, 255, y * 42, 1)
#Rotate everything left 36 frames
for i in range(0, 36):
dotstar.shift_down(True)
# Draw dual gradiant and then update
dotstar.auto_write = False
for y in range(0, dotstar.rows):
for x in range(0, 6):
dotstar[x, y] = (y * 84, x * 42, x * 42, 1)
for x in range(6, 12):
dotstar[x, y] = (255 - (y * 84), 255 - ((x - 6) * 42), 255 - ((x - 6) * 42), 1)
# Rotate everything left 36 frames
for i in range(0, 36):
dotstar.shift_left(True)
dotstar.shift_up(True)
dotstar.show()
dotstar.auto_write = True
# Shift pixels without rotating for an animated screen wipe
for i in range(0, 6):
dotstar.shift_down()
# Show pixels in random locations of random color
# Bottom left corner is (0,0)
while True:
x = random.randrange(0, dotstar.columns)
y = random.randrange(0, dotstar.rows)
dotstar[x, y] = (random_color(), random_color(), random_color())
sleep(.1)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | """
This example plays various animations
and then draws random pixels at random locations
"""
from time import sleep
import random
from adafruit_featherwing import neopixel_featherwing
neopixel = neopixel_featherwing.NeoPixelFeatherWing()
# HELPERS
# a random color 0 -> 224
def random_color():
return random.randrange(0, 8) * 32
# Fill screen with random colors at random brightnesses
for i in range(0, 5):
neopixel.fill((random_color(), random_color(), random_color()))
neopixel.brightness = random.randrange(2, 10) / 10
sleep(.2)
# Set display to 30% brightness
neopixel.brightness = 0.3
# Create a gradiant drawing each pixel
for x in range(0, neopixel.columns):
for y in range(neopixel.rows - 1, -1, -1):
neopixel[x, y] = (y * 63, 255, y * 63)
#Rotate everything left 36 frames
for i in range(0, 36):
neopixel.shift_down(True)
sleep(0.1)
# Draw dual gradiant and then update
#neopixel.auto_write = False
for y in range(0, neopixel.rows):
for x in range(0, 4):
neopixel[x, y] = (y * 16 + 32, x * 8, 0)
for x in range(4, 8):
neopixel[x, y] = ((4 - y) * 16 + 32, (8 - x) * 8, 0)
neopixel.show()
# Rotate everything left 36 frames
for i in range(0, 36):
neopixel.shift_left(True)
neopixel.shift_up(True)
neopixel.show()
sleep(0.1)
neopixel.auto_write = True
# Shift pixels without rotating for an animated screen wipe
for i in range(0, neopixel.rows):
neopixel.shift_down()
sleep(0.4)
# Show pixels in random locations of random color
# Bottom left corner is (0,0)
while True:
x = random.randrange(0, neopixel.columns)
y = random.randrange(0, neopixel.rows)
neopixel[x, y] = (random_color(), random_color(), random_color())
sleep(.1)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | """This example changes the fill, brightness, blink rates,
shows number and text printing, displays a counter
and then shows off the new marquee features."""
from time import sleep
from adafruit_featherwing import sevensegment_featherwing
display = sevensegment_featherwing.SevenSegmentFeatherWing()
#Fill and empty all segments
for count in range(0, 3):
display.fill(True)
sleep(0.5)
display.fill(False)
sleep(0.5)
#Display a number and text
display.print(1234)
sleep(1)
display.print('FEED')
#Change brightness
for brightness in range(0, 16):
display.brightness = brightness
sleep(0.1)
#Change blink rate
for blink_rate in range(3, 0, -1):
display.blink_rate = blink_rate
sleep(4)
display.blink_rate = 0
#Show a counter using decimals
count = 975.0
while count < 1025:
count += 1
display.print(count)
sleep(0.1)
#Display a Time
hour = 12
for minute in range(15, 26):
display.print("{}:{}".format(hour, minute))
sleep(1)
#Show the Marquee
display.marquee('Deadbeef 192.168.100.102... ', 0.2)
|
Other tests¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | """
This creates a palette of colors, draws a pattern and
rotates through the palette creating a moving rainbow.
"""
from math import sqrt, cos, sin, radians
from adafruit_featherwing import dotstar_featherwing
dotstar = dotstar_featherwing.DotStarFeatherWing()
# Remap the calculated rotation to 0 - 255
def remap(vector):
return int(((255 * vector + 85) * 0.75) + 0.5)
# Calculate the Hue rotation starting with Red as 0 degrees
def rotate(degrees):
cosA = cos(radians(degrees))
sinA = sin(radians(degrees))
red = cosA + (1.0 - cosA) / 3.0
green = 1./3. * (1.0 - cosA) + sqrt(1./3.) * sinA
blue = 1./3. * (1.0 - cosA) - sqrt(1./3.) * sinA
return (remap(red), remap(green), remap(blue))
palette = []
pixels = []
# Generate a rainbow palette
for degree in range(0, 360):
color = rotate(degree)
palette.append(color[0] << 16 | color[1] << 8 | color[2])
# Create the Pattern
for y in range(0, dotstar.rows):
for x in range(0, dotstar.columns):
pixels.append(x * 30 + y * -30)
# Clear the screen
dotstar.fill()
# Start the Animation
dotstar.auto_write = False
while True:
for color in range(0, 360, 10):
for index in range(0, dotstar.rows * dotstar.columns):
palette_index = pixels[index] + color
if palette_index >= 360:
palette_index -= 360
elif palette_index < 0:
palette_index += 360
dotstar[index] = palette[palette_index]
dotstar.show()
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | """
This creates a palette of colors, draws a pattern and
rotates through the palette creating a moving rainbow.
"""
from math import sqrt, cos, sin, radians
from adafruit_featherwing import neopixel_featherwing
neopixel = neopixel_featherwing.NeoPixelFeatherWing()
# Remap the calculated rotation to 0 - 255
def remap(vector):
return int(((255 * vector + 85) * 0.75) + 0.5)
# Calculate the Hue rotation starting with Red as 0 degrees
def rotate(degrees):
cosA = cos(radians(degrees))
sinA = sin(radians(degrees))
red = cosA + (1.0 - cosA) / 3.0
green = 1./3. * (1.0 - cosA) + sqrt(1./3.) * sinA
blue = 1./3. * (1.0 - cosA) - sqrt(1./3.) * sinA
return (remap(red), remap(green), remap(blue))
palette = []
pixels = []
# Generate a rainbow palette
for degree in range(0, 360):
color = rotate(degree)
palette.append(color[0] << 16 | color[1] << 8 | color[2])
# Create the Pattern
for y in range(0, neopixel.rows):
for x in range(0, neopixel.columns):
pixels.append(x * 30 + y * -30)
# Clear the screen
neopixel.fill()
# Start the Animation
neopixel.auto_write = False
while True:
for color in range(0, 360, 10):
for index in range(0, neopixel.rows * neopixel.columns):
palette_index = pixels[index] + color
if palette_index >= 360:
palette_index -= 360
elif palette_index < 0:
palette_index += 360
neopixel[index] = palette[palette_index]
neopixel.show()
|