コード例 #1
0
ファイル: train_board.py プロジェクト: patelpp/dc-metro
class TrainBoard:
    """
		get_new_data is a function that is expected to return an array of dictionaries like this:

		[
			{
				'line_color': 0xFFFFFF,
				'destination': 'Dest Str',
				'arrival': '5'
			}
		]
	"""
    def __init__(self, get_new_data):
        self.get_new_data = get_new_data

        self.display = Matrix().display

        self.parent_group = displayio.Group(max_size=5)

        self.heading_label = Label(config['font'],
                                   max_glyphs=len(config['heading_text']),
                                   anchor_point=(0, 0))
        self.heading_label.color = config['heading_color']
        self.heading_label.text = config['heading_text']
        self.parent_group.append(self.heading_label)

        self.trains = []
        for i in range(config['num_trains']):
            self.trains.append(Train(self.parent_group, i))

        self.display.show(self.parent_group)

    def refresh(self) -> bool:
        print('Refreshing train information...')
        train_data = self.get_new_data()

        if train_data is not None:
            print('Reply received.')
            for i in range(config['num_trains']):
                if i < len(train_data):
                    train = train_data[i]
                    self._update_train(i, train['line_color'],
                                       train['destination'], train['arrival'])
                else:
                    self._hide_train(i)

            print('Successfully updated.')
        else:
            print('No data received. Clearing display.')

            for i in range(config['num_trains']):
                self._hide_train(i)

    def _hide_train(self, index: int):
        self.trains[index].hide()

    def _update_train(self, index: int, line_color: int, destination: str,
                      minutes: str):
        self.trains[index].update(line_color, destination, minutes)
コード例 #2
0
ファイル: train_board.py プロジェクト: patelpp/dc-metro
    def __init__(self, get_new_data):
        self.get_new_data = get_new_data

        self.display = Matrix().display

        self.parent_group = displayio.Group(max_size=5)

        self.heading_label = Label(config['font'],
                                   max_glyphs=len(config['heading_text']),
                                   anchor_point=(0, 0))
        self.heading_label.color = config['heading_color']
        self.heading_label.text = config['heading_text']
        self.parent_group.append(self.heading_label)

        self.trains = []
        for i in range(config['num_trains']):
            self.trains.append(Train(self.parent_group, i))

        self.display.show(self.parent_group)
コード例 #3
0
    def __init__(
        self,
        **kwargs,
    ):
        default_bg = 0x000000
        debug = False
        if "default_bg" in kwargs:
            default_bg = kwargs.pop("default_bg")
        if "debug" in kwargs:
            debug = kwargs.pop("debug")

        matrix = Matrix(**kwargs)

        super().__init__(matrix.display, default_bg=default_bg, debug=debug)
コード例 #4
0
ファイル: code.py プロジェクト: mikejc58/MatrixClock
 def __init__(self):
     self.group = displayio.Group(max_size=4)
     self.font = bitmap_font.load_font("/IBMPlexMono-Medium-24_jep.bdf")
     self.font.load_glyphs('0123456789')
     self.hour_label = Label(self.font, max_glyphs=2)
     self.min_label = Label(self.font, max_glyphs=2)
     self.colon_label = Label(self.font, max_glyphs=1)
     self.setup_AM_PM()
     self.group.append(self.colon_label)
     self.group.append(self.hour_label)
     self.group.append(self.min_label)
     self.group.append(self.AM_PM_TileGrid)
     
     self.matrix = Matrix(bit_depth=5)   # bit_depth=5 allows 32 levels for each of R,G, and B
コード例 #5
0
ファイル: main.py プロジェクト: cjdaly/CompuCanvasMP
def init(cc_state):
    CCMP_model = cc_state['config']['CCMP_model']
    width = 32
    height = 32
    if CCMP_model == '64x':
        width = 64
        height = 64
        cc_state['width'] = 64
        cc_state['height'] = 64
    elif CCMP_model == '64h':
        width = 64
        height = 32
        cc_state['width'] = 64
        cc_state['height'] = 32
    elif CCMP_model == '64v':
        width = 64
        height = 32
        cc_state['width'] = 32
        cc_state['height'] = 64
    else:
        cc_state['width'] = 32
        cc_state['height'] = 32
    #
    matrix = Matrix(width=width, height=height, bit_depth=6)
    cc_state['matrix'] = matrix
    matrix.display.rotation = cc_state['config']['rotation']
    #
    root_group = displayio.Group(max_size=12)
    root_group.append(
        Rect(0,
             0,
             cc_state['width'],
             cc_state['height'],
             fill=0x001020,
             outline=0x444444))
    cc_state['groups']['ROOT'] = root_group
    #
    cc_state['fonts']['terminal'] = terminalio.FONT
    cc_state['fonts']['helvB12'] = bitmap_font.load_font('/fonts/helvB12.bdf')
    cc_state['fonts']['helvR10'] = bitmap_font.load_font('/fonts/helvR10.bdf')
    #
    cc_state['buttons']['up'] = digitalio.DigitalInOut(board.BUTTON_UP)
    cc_state['buttons']['up'].switch_to_input(digitalio.Pull.UP)
    cc_state['buttons']['down'] = digitalio.DigitalInOut(board.BUTTON_DOWN)
    cc_state['buttons']['down'].switch_to_input(digitalio.Pull.UP)
    cc_state['buttons']['counter'] = 0
    #
    matrix.display.show(root_group)
コード例 #6
0
    def __init__(
        self,
        *,
        default_bg=0x000000,
        width=64,
        height=32,
        bit_depth=2,
        alt_addr_pins=None,
        color_order="RGB",
        debug=False
    ):

        self._debug = debug
        matrix = Matrix(
            bit_depth=bit_depth,
            width=width,
            height=height,
            alt_addr_pins=alt_addr_pins,
            color_order=color_order,
        )
        self.display = matrix.display

        if self._debug:
            print("Init display")
        self.splash = displayio.Group(max_size=15)

        if self._debug:
            print("Init background")
        self._bg_group = displayio.Group(max_size=1)
        self._bg_file = None
        self._default_bg = default_bg
        self.splash.append(self._bg_group)

        # set the default background
        self.set_background(self._default_bg)
        self.display.show(self.splash)

        gc.collect()
コード例 #7
0
'''
Display will go to sleep after SLEEP_DURATION seconds have elapsed with no accelerometer movement
Each slide will play for IMAGE_DURATION - customizable for each folder
Add folders to the list to add more slideshows.
'''

SLEEP_DURATION = 60
IMAGE_DURATION = (1, 0.5, 10)
IMAGE_FOLDER = (
    "/bmps",
    "/bmps2",
    "/bmps3",
)
# pylint: disable=invalid-name
# --- Display setup ---
matrix = Matrix(bit_depth=6)
display = matrix.display
ACCEL = adafruit_lis3dh.LIS3DH_I2C(busio.I2C(board.SCL, board.SDA),
                                   address=0x19)
_ = ACCEL.acceleration  # Dummy reading to blow out any startup residue

pin_down = DigitalInOut(board.BUTTON_DOWN)
pin_down.switch_to_input(pull=Pull.UP)
button_down = Debouncer(pin_down)
pin_up = DigitalInOut(board.BUTTON_UP)
pin_up.switch_to_input(pull=Pull.UP)
button_up = Debouncer(pin_up)

ALIGN_RIGHT = True
auto_advance = True
コード例 #8
0
import adafruit_scd30

# --| User Config |----
CO2_CUTOFFS = (1000, 2000, 5000)
UPDATE_RATE = 1
# ---------------------

# the sensor
scd30 = adafruit_scd30.SCD30(board.I2C())

# optional if known (pick one)
# scd30.ambient_pressure = 1013.25
# scd30.altitude = 0

# the display
matrix = Matrix(width=64, height=32, bit_depth=6)
display = matrix.display
display.rotation = 90  # matrixportal up
# display.rotation = 270 # matrixportal down

# current condition smiley face
smileys_bmp, smileys_pal = adafruit_imageload.load("/bmps/smileys.bmp")
smiley = displayio.TileGrid(
    smileys_bmp,
    pixel_shader=smileys_pal,
    x=0,
    y=0,
    width=1,
    height=1,
    tile_width=32,
    tile_height=32,
コード例 #9
0
    'Green': 0x006600,
    'Blue': 0x000066,
    'Violet': 0x663666,
    'White': 0x444444,
}

# Get wifi details and more from a secrets.py file
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise
print("Matrix Clock Plus")

# --- Display setup ---
matrix = Matrix()
display = matrix.display
network = Network(status_neopixel=board.NEOPIXEL, debug=False)
button_down = DigitalInOut(board.BUTTON_DOWN)
button_down.switch_to_input(pull=Pull.UP)
button_up = DigitalInOut(board.BUTTON_UP)
button_up.switch_to_input(pull=Pull.UP)

# --- Weather data setup ---
UNITS = "imperial"
DATA_LOCATION = []
DATA_SOURCE = ("http://api.openweathermap.org/data/2.5/weather?q=" +
               secrets["openweather_loc"] + "&units=" + UNITS)
DATA_SOURCE += "&appid=" + secrets["openweather_token"]
current_temp = '0'
コード例 #10
0
    (0, 23),
    (0, 26),
    (0, 29),
)
MATRIX_WIDTH = 64
MATRIX_HEIGHT = 32
BACK_COLOR = 0x000000  # background fill
SING_COLOR = 0xADAF00  # singularities
HEAD_COLOR = 0x00FFFF  # leading particles
TAIL_COLOR = 0x000A0A  # trailing particles
TAIL_LENGTH = 10  # length in pixels
DELAY = 0.01  # smaller = faster
#----------------------------------------------------------

# matrix and displayio setup
matrix = Matrix(width=MATRIX_WIDTH, height=MATRIX_HEIGHT, bit_depth=6)
display = matrix.display
group = displayio.Group()
display.show(group)

bitmap = displayio.Bitmap(display.width, display.height, 4)

palette = displayio.Palette(4)
palette[0] = BACK_COLOR
palette[1] = SING_COLOR
palette[2] = HEAD_COLOR
palette[3] = TAIL_COLOR

tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)
group.append(tile_grid)
コード例 #11
0
                    self.rise = None
                if 'moonset' in moon_data:
                    self.set = time.mktime(
                        parse_time(moon_data['moonset']['time']))
                else:
                    self.set = None
                return # Success!
            except:
                # Moon server error (maybe), try again after 15 seconds.
                # (Might be a memory error, that should be handled different)
                time.sleep(15)


# ONE-TIME INITIALIZATION --------------------------------------------------

MATRIX = Matrix(bit_depth=BITPLANES)
DISPLAY = MATRIX.display
ACCEL = adafruit_lis3dh.LIS3DH_I2C(busio.I2C(board.SCL, board.SDA),
                                   address=0x19)
_ = ACCEL.acceleration # Dummy reading to blow out any startup residue
time.sleep(0.1)
DISPLAY.rotation = (int(((math.atan2(-ACCEL.acceleration.y,
                                     -ACCEL.acceleration.x) + math.pi) /
                         (math.pi * 2) + 0.875) * 4) % 4) * 90

LARGE_FONT = bitmap_font.load_font('/fonts/helvB12.bdf')
SMALL_FONT = bitmap_font.load_font('/fonts/helvR10.bdf')
SYMBOL_FONT = bitmap_font.load_font('/fonts/6x10.bdf')
LARGE_FONT.load_glyphs('0123456789:')
SMALL_FONT.load_glyphs('0123456789:/.%')
SYMBOL_FONT.load_glyphs('\u21A5\u21A7')
コード例 #12
0
                         transparent[2] - (color & 0xFF))
                rgb_distance = (delta[0] * delta[0] + delta[1] * delta[1] +
                                delta[2] * delta[2])  # Actually dist^2
                if rgb_distance < closest_distance:  # but adequate for
                    closest_distance = rgb_distance  # compare purposes,
                    closest_index = color_index  # no sqrt needed
            palette.make_transparent(closest_index)
        elif isinstance(transparent, int):
            palette.make_transparent(transparent)
        super(Sprite, self).__init__(bitmap, pixel_shader=palette)
        self.height = bitmap.height


# ONE-TIME INITIALIZATION --------------------------------------------------

MATRIX = Matrix(bit_depth=6, width=96, height=32)
DISPLAY = MATRIX.display

# Order in which sprites are added determines the 'stacking order' and
# visual priority. Lower lid is added before the upper lid so that if they
# overlap, the upper lid is 'on top' (e.g. if it has eyelashes or such).
SPRITES = displayio.Group(max_size=5)
SPRITES.append(Sprite(EYE_DATA['eye_image']))  # Base image is opaque
SPRITES.append(Sprite(EYE_DATA['lower_lid_image'], EYE_DATA['transparent']))
SPRITES.append(Sprite(EYE_DATA['upper_lid_image'], EYE_DATA['transparent']))
SPRITES.append(Sprite(EYE_DATA['background_image'], EYE_DATA['transparent']))
SPRITES.append(Sprite(EYE_DATA['stencil_image'], EYE_DATA['transparent']))

DISPLAY.show(SPRITES)

EYE_CENTER = (
コード例 #13
0
                         transparent[2] - (color & 0xFF))
                rgb_distance = (delta[0] * delta[0] + delta[1] * delta[1] +
                                delta[2] * delta[2])  # Actually dist^2
                if rgb_distance < closest_distance:  # but adequate for
                    closest_distance = rgb_distance  # compare purposes,
                    closest_index = color_index  # no sqrt needed
            palette.make_transparent(closest_index)
        elif isinstance(transparent, int):
            palette.make_transparent(transparent)
        super(Sprite, self).__init__(bitmap, pixel_shader=palette)
        self.height = bitmap.height


# ONE-TIME INITIALIZATION --------------------------------------------------

MATRIX = Matrix(bit_depth=6)
DISPLAY = MATRIX.display

# Order in which sprites are added determines the 'stacking order' and
# visual priority. Lower lid is added before the upper lid so that if they
# overlap, the upper lid is 'on top' (e.g. if it has eyelashes or such).
SPRITES = displayio.Group()
SPRITES.append(Sprite(EYE_DATA['eye_image']))  # Base image is opaque
SPRITES.append(Sprite(EYE_DATA['lower_lid_image'], EYE_DATA['transparent']))
SPRITES.append(Sprite(EYE_DATA['upper_lid_image'], EYE_DATA['transparent']))
SPRITES.append(Sprite(EYE_DATA['stencil_image'], EYE_DATA['transparent']))
DISPLAY.show(SPRITES)

EYE_CENTER = (
    (
        EYE_DATA['eye_move_min'][0] +  # Pixel coords of eye
コード例 #14
0
#  import your bearer token
bear = secrets['bearer_token']

#  query URL for tweets. looking for hashtag partyparrot sent to a specific username
DATA_SOURCE = 'https://api.twitter.com/2/tweets/search/recent?query=#partyparrot to:blitzcitydiy'
#  json data path to get most recent tweet's ID number
DATA_LOCATION = ["meta", "newest_id"]

#  create MatrixPortal object to grab data/connect to internet
matrixportal = MatrixPortal(url=DATA_SOURCE,
                            json_path=DATA_LOCATION,
                            status_neopixel=board.NEOPIXEL)

#  create matrix display
matrix = Matrix(width=32, height=32)
display = matrix.display

group = displayio.Group()

#  load in party parrot bitmap
parrot_bit, parrot_pal = adafruit_imageload.load("/partyParrotsTweet.bmp",
                                                 bitmap=displayio.Bitmap,
                                                 palette=displayio.Palette)

parrot_grid = displayio.TileGrid(parrot_bit,
                                 pixel_shader=parrot_pal,
                                 width=1,
                                 height=1,
                                 tile_height=32,
                                 tile_width=32,
コード例 #15
0
from adafruit_matrixportal.network import Network
from adafruit_matrixportal.matrix import Matrix
import vectorio
from new_year import NEW_YEAR

BIT_DEPTH = 6
BLINK = True
DEBUG = False
global year
year = 2020

from secrets import secrets
print("Time will be set for {}".format(secrets["timezone"]))

# --- Display setup ---
matrix = Matrix(bit_depth=BIT_DEPTH)
display = matrix.display
display.brightness = 0.8
network = Network(debug=DEBUG)
BITMAP = displayio.OnDiskBitmap(open('balldrop.bmp', 'rb'))

TILE_GRID = displayio.TileGrid(
    BITMAP,
    pixel_shader=displayio.ColorConverter(),
)


class RowCountdown:
    def __init__(self, display, displayio):
        # --- Drawing setup ---
        self.group = displayio.Group(max_size=10)  # Create a Group
コード例 #16
0
import time
import board
import displayio
from adafruit_matrixportal.matrix import Matrix
import adafruit_imageload

# What are the dimensions of your LED Matrix?
matrix_width = 32
matrix_height = 32

# How fast should we flip between images?
animation_speed = 0.1  # speed between frames in fractional seconds

#  create matrix display
#  I also added a bit_depth to make more colors pop out
matrix = Matrix(width=matrix_width, height=matrix_height, bit_depth=6)
display = matrix.display

#  load in bitmap (image_bit), and colors into a pallet (image_pal)
#  The file you are loading in is in the quotation marks
#  Make sure it's a .bmp with 8 bit format, otherwise it won't work
#  I edited mine in Photoshop. Settings:
#  Image > Mode > Indexed Color
#  Save As: Format BMP, (next screen) File Format: Windows, Depth: 8 bit

# All bitmaps for this project assume 32 x 32 LED Display.
# Some of the bitmaps in the GitHub repo for this project:
# "swift", "full-animation",
# "raspberry-adafruit-animated", "animated_arduino",
# "swift-maker-animation", "animated-excel",
# "partyParrotsMatrix", "ghost-animation"