Ejemplo n.º 1
0
                             ],
                             addr_pins=[
                                 board.MTX_ADDRA, board.MTX_ADDRB,
                                 board.MTX_ADDRC, board.MTX_ADDRD
                             ],
                             clock_pin=board.MTX_CLK,
                             latch_pin=board.MTX_LAT,
                             output_enable_pin=board.MTX_OE)
display = framebufferio.FramebufferDisplay(matrix, auto_refresh=False)
SCALE = 1
palette = displayio.Palette(8)
b1 = displayio.Bitmap(display.width // SCALE, display.height // SCALE,
                      len(palette))
b2 = displayio.Bitmap(display.width // SCALE, display.height // SCALE,
                      len(palette))
tg1 = displayio.TileGrid(b1, pixel_shader=palette)
tg2 = displayio.TileGrid(b2, pixel_shader=palette)
g1 = displayio.Group(max_size=3, scale=SCALE)
g1.append(tg1)
display.show(g1)
g2 = displayio.Group(max_size=3, scale=SCALE)
g2.append(tg2)

board1 = [b1, []]
board2 = [b2, []]
for idx in range(b1.width * b1.height):
    board1[1].append(False)
    board2[1].append(False)

# First time, show the Conway tribute
for idx in range(1, len(palette)):
Ejemplo n.º 2
0
audio = AudioOut(board.A0)

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

group = displayio.Group()

#  import dreidel bitmap
dreidel_bit, dreidel_pal = adafruit_imageload.load("/dreidel.bmp",
                                                 bitmap=displayio.Bitmap,
                                                 palette=displayio.Palette)

dreidel_grid = displayio.TileGrid(dreidel_bit, pixel_shader=dreidel_pal,
                                 width=1, height=1,
                                 tile_height=32, tile_width=32,
                                 default_tile=0,
                                 x=0, y=0)

group.append(dreidel_grid)

#  show dreidel bitmap
display.show(group)

timer = 0 #  time.monotonic() holder
spin = 0 #  index for tilegrid
speed = 0.1 #  rate that bitmap updates
clock = 0 #  initial time.monotonic() holder to act as time keeper
gimel = 3 #  bitmap index for gimel, the winning character
countdown = 5 #  countdown for length of game. default is 5 seconds
beam_state = False #  state machine for break beam
epd_cs = board.D10
epd_dc = board.D9

display_bus = displayio.FourWire(spi,
                                 command=epd_dc,
                                 chip_select=epd_cs,
                                 baudrate=1000000)
time.sleep(1)

display = adafruit_il91874.IL91874(display_bus,
                                   width=264,
                                   height=176,
                                   highlight_color=0xff0000,
                                   rotation=90)

g = displayio.Group()

f = open("/display-ruler.bmp", "rb")

pic = displayio.OnDiskBitmap(f)
t = displayio.TileGrid(pic, pixel_shader=displayio.ColorConverter())
g.append(t)

display.show(g)

display.refresh()

print("refreshed")

time.sleep(120)
Ejemplo n.º 4
0
display_bus = displayio.FourWire(spi,
                                 command=epd_dc,
                                 chip_select=epd_cs,
                                 reset=epd_reset,
                                 baudrate=1000000)
time.sleep(1)

display = adafruit_il0398.IL0398(display_bus,
                                 width=400,
                                 height=300,
                                 seconds_per_frame=20,
                                 busy_pin=epd_busy)

g = displayio.Group()

with open("/display-ruler.bmp", "rb") as f:
    pic = displayio.OnDiskBitmap(f)
    # CircuitPython 6 & 7 compatible
    t = displayio.TileGrid(pic,
                           pixel_shader=getattr(pic, "pixel_shader",
                                                displayio.ColorConverter()))
    # CircuitPython 7 compatible only
    # t = displayio.TileGrid(pic, pixel_shader=pic.pixel_shader)
    g.append(t)

    display.show(g)

    display.refresh()

    time.sleep(120)
Ejemplo n.º 5
0
##########################################################################
THE_FONT = fonts[0]
DISPLAY_STRING = "A multi-line-\nexample of\n  font bounding!"
WRAP_CHARS = 40

##########################################################################
# Make the display context
splash = displayio.Group()
board.DISPLAY.show(splash)

# Make a background color fill
color_bitmap = displayio.Bitmap(320, 240, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFFFFFF
bg_sprite = displayio.TileGrid(color_bitmap,
                               pixel_shader=color_palette,
                               x=0,
                               y=0)
splash.append(bg_sprite)

# Load the font
font = bitmap_font.load_font(THE_FONT)
font.load_glyphs(DISPLAY_STRING.encode('utf-8'))

print(DISPLAY_STRING)

text = Label(font, text=DISPLAY_STRING)
text.x = 20
text.y = 100
text.color = 0x0

# Make a background color fill
def menu_choice(seq, button_ok, button_cancel=0, *, sel_idx=0, text_font=font):
    """Display a menu and allow a choice from it"""
    gc.collect()
    board.DISPLAY.auto_refresh = True
    scroll_idx = 0
    glyph_width, glyph_height = text_font.get_bounding_box()[:2]
    num_rows = min(len(seq), board.DISPLAY.height // glyph_height)
    max_glyphs = board.DISPLAY.width // glyph_width
    palette = displayio.Palette(2)
    palette[0] = 0
    palette[1] = 0xffffff
    labels = [displayio.TileGrid(text_font.bitmap, pixel_shader=palette,
                                 width=max_glyphs+1, height=1,
                                 tile_width=glyph_width,
                                 tile_height=glyph_height)
              for i in range(num_rows)]
    terminals = [terminalio.Terminal(li, text_font) for li in labels]
    cursor = adafruit_display_text.label.Label(text_font, max_glyphs=1, color=0xddddff)
    base_y = 0
    caret_offset = glyph_height//2-1
    scene = displayio.Group(max_size=len(labels) + 1)
    for i, label in enumerate(labels):
        label.x = round(glyph_width * 1.5)
        label.y = base_y + glyph_height * i
        scene.append(label)
    cursor.x = 0
    cursor.y = caret_offset
    cursor.text = ">"
    scene.append(cursor)

    last_scroll_idx = max(0, len(seq) - num_rows)

    board.DISPLAY.show(scene)
    buttons.get_pressed() # Clear out anything from before now
    i = 0
    old_scroll_idx = None

    while True:
        enable.value = speaker.playing
        pressed = buttons.get_pressed()
        if button_cancel and (pressed & button_cancel):
            return -1
        if pressed & button_ok:
            return sel_idx

        joystick.poll()
        if up_key.value:
            sel_idx -= 1
        if down_key.value:
            sel_idx += 1

        sel_idx = min(len(seq)-1, max(0, sel_idx))

        if scroll_idx > sel_idx or scroll_idx + num_rows <= sel_idx:
            scroll_idx = sel_idx - num_rows // 2
        scroll_idx = min(last_scroll_idx, max(0, scroll_idx))

        board.DISPLAY.auto_refresh = False
        if old_scroll_idx != scroll_idx:
            for i in range(scroll_idx, scroll_idx + num_rows):
                j = i - scroll_idx
                new_text = ''
                if i < len(seq):
                    new_text = seq[i][:max_glyphs]
                terminals[j].write('\r\033[K')
                terminals[j].write(new_text)
        cursor.y = caret_offset + base_y + glyph_height * (sel_idx - scroll_idx)
        board.DISPLAY.auto_refresh = True
        old_scroll_idx = scroll_idx

        time.sleep(1/20)
Ejemplo n.º 7
0
def load_map(mapname, x=0, y=0):
  f = open("/maps/" + mapname + "/" + mapname + ".bmp", "rb")
  odb = displayio.OnDiskBitmap(f)
  tg=displayio.TileGrid(odb, pixel_shader=displayio.ColorConverter(), position=(0,0))
  tg.position=(x,y)
  return tg
Ejemplo n.º 8
0
    clock_pin=board.D13,
    latch_pin=board.D0,
    output_enable_pin=board.D1,
)
display = framebufferio.FramebufferDisplay(matrix)
matrix.brightness = 0.05

group = displayio.Group(max_size=20)

parrot, parrot_pal = adafruit_imageload.load("/partyParrotsMatrix.bmp",
                                             bitmap=displayio.Bitmap,
                                             palette=displayio.Palette)

parrot0_grid = displayio.TileGrid(parrot, pixel_shader=parrot_pal,
                                 width=1, height=1,
                                 tile_height=32, tile_width=32,
                                 default_tile=0,
                                 x=0, y=0)

group.append(parrot0_grid)

display.show(group)

party0 = 0
p = 0

while True:
    if (party0 + 0.1) < time.monotonic():

        parrot0_grid[0] = p
Ejemplo n.º 9
0
    def _update_text(self, new_text):  # pylint: disable=too-many-locals
        x = 0
        y = 0
        i = 1
        old_c = 0
        y_offset = int(
            (self._font.get_glyph(ord("M")).height -
             new_text.count("\n") * self.height * self.line_spacing) / 2)
        left = right = top = bottom = 0
        lines = 1
        for character in new_text:
            if character == "\n":
                y += int(self.height * self._line_spacing)
                x = 0
                lines += 1
                continue
            glyph = self._font.get_glyph(ord(character))
            if not glyph:
                continue
            right = max(right, x + glyph.shift_x)
            if y == 0:  # first line, find the Ascender height
                top = min(top, -glyph.height - glyph.dy + y_offset)
            bottom = max(bottom, y - glyph.dy + y_offset)
            position_y = y - glyph.height - glyph.dy + y_offset
            position_x = x + glyph.dx
            if (not self._text or old_c >= len(self._text)
                    or character != self._text[old_c]):
                try:
                    face = displayio.TileGrid(
                        glyph.bitmap,
                        pixel_shader=self.palette,
                        default_tile=glyph.tile_index,
                        tile_width=glyph.width,
                        tile_height=glyph.height,
                        position=(position_x, position_y),
                    )
                except TypeError:
                    face = displayio.TileGrid(
                        glyph.bitmap,
                        pixel_shader=self.palette,
                        default_tile=glyph.tile_index,
                        tile_width=glyph.width,
                        tile_height=glyph.height,
                        x=position_x,
                        y=position_y,
                    )
                if i < len(self):
                    self[i] = face
                else:
                    self.append(face)
            elif self._text and character == self._text[old_c]:

                try:
                    self[i].position = (position_x, position_y)
                except AttributeError:
                    self[i].x = position_x
                    self[i].y = position_y

            x += glyph.shift_x
            # TODO skip this for control sequences or non-printables.
            i += 1
            old_c += 1
            # skip all non-printables in the old string
            while (self._text and old_c < len(self._text)
                   and (self._text[old_c] == "\n"
                        or not self._font.get_glyph(ord(self._text[old_c])))):
                old_c += 1
        # Remove the rest
        while len(self) > i:
            self.pop()
        self._text = new_text
        self._boundingbox = (left, top, left + right, bottom - top)
        self[0] = self._create_background_box(lines, y_offset)
Ejemplo n.º 10
0
            )
            green = int(
                round((color[idx2][1] - color[idx1][1]) * fractBetween + color[idx1][1])
            )
            blue = int(
                round((color[idx2][2] - color[idx1][2]) * fractBetween + color[idx1][2])
            )
        palette[c] = (0x010000 * red) + (0x000100 * green) + (0x000001 * blue)


MakeHeatMapColor()

# Bitmap for colour coded thermal value
image_bitmap = displayio.Bitmap(32, 24, number_of_colors)
# Create a TileGrid using the Bitmap and Palette
image_tile = displayio.TileGrid(image_bitmap, pixel_shader=palette)
# Create a Group that scale 32*24 to 128*96
image_group = displayio.Group(scale=4)
image_group.append(image_tile)

scale_bitmap = displayio.Bitmap(number_of_colors, 1, number_of_colors)
# Create a Group Scale must be 128 divided by number_of_colors
scale_group = displayio.Group(scale=2)
scale_tile = displayio.TileGrid(scale_bitmap, pixel_shader=palette, x=0, y=60)
scale_group.append(scale_tile)

for i in range(number_of_colors):
    scale_bitmap[i, 0] = i  # Fill the scale with the palette gradian

# Create the super Group
group = displayio.Group()
tft_dc = board.D25

display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = ST7789(
    display_bus, rotation=90, width=240, height=135, rowstart=40, colstart=53
)

# Make the display context
splash = displayio.Group(max_size=10)
display.show(splash)

color_bitmap = displayio.Bitmap(display.width, display.height, 1)
color_palette = displayio.Palette(1)
color_palette[0] = BACKGROUND_COLOR

bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)

# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(
    display.width - BORDER * 2, display.height - BORDER * 2, 1
)
inner_palette = displayio.Palette(1)
inner_palette[0] = FOREGROUND_COLOR
inner_sprite = displayio.TileGrid(
    inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
)
splash.append(inner_sprite)

# Draw a label
text = "Hello World!"
Ejemplo n.º 12
0
    def aws_announcements(self,
                          *,
                          background_color=0xFF9900,
                          foreground_color=0xFFFFFF,
                          background_text_color=0x000000,
                          foreground_text_color=0x000000,
                          hello_font=terminalio.FONT,
                          hello_scale=1,
                          my_name_is_font=terminalio.FONT,
                          my_name_is_scale=1,
                          my_name_is_string="MY NAME IS",
                          name_font=terminalio.FONT,
                          name_scale=1,
                          name_string="Blinka"):

        splash = displayio.Group(max_size=20)

        color_bitmap = displayio.Bitmap(self.display.width,
                                        self.display.height, 1)
        color_palette = displayio.Palette(1)
        color_palette[0] = background_color

        bg_sprite = displayio.TileGrid(color_bitmap,
                                       pixel_shader=color_palette,
                                       x=0,
                                       y=0)
        splash.append(bg_sprite)

        rect = Rect(0, (int(self.display.height * 0.5)),
                    self.display.width, (int(self.display.height * 0.5)),
                    fill=foreground_color)
        splash.append(rect)

        # Header
        header_string = "re:Invent"
        hello_font_name = "/fonts/Verdana-Bold-18.bdf"
        hello_font = bitmap_font.load_font(hello_font_name)
        hello_font.load_glyphs(header_string.encode('utf-8'))

        hello_scale = hello_scale
        hello_group = displayio.Group(scale=hello_scale)
        hello_label = Label(font=hello_font, text=header_string)
        (_, _, width, height) = hello_label.bounding_box
        hello_label.x = ((self.display.width // (2 * hello_scale)) -
                         width // 2)
        hello_label.y = int(height // (1.2 * hello_scale))
        hello_label.color = background_text_color
        hello_group.append(hello_label)

        # Subheader
        my_name_is_string = "Announcements"
        my_name_is_string2 = "this week"
        my_name_is_font_name = "/fonts/Arial-12.bdf"
        my_name_is_font = bitmap_font.load_font(my_name_is_font_name)
        my_name_is_font.load_glyphs(my_name_is_string.encode('utf-8'))
        my_name_is_font.load_glyphs(my_name_is_string2.encode('utf-8'))

        my_name_is_scale = my_name_is_scale
        my_name_is_group = displayio.Group(scale=my_name_is_scale)
        my_name_is_label = Label(font=my_name_is_font, text=my_name_is_string)
        (_, _, width, height) = my_name_is_label.bounding_box
        my_name_is_label.x = ((self.display.width // (2 * my_name_is_scale)) -
                              width // 2)
        my_name_is_label.y = int(height // (0.32 * my_name_is_scale))
        my_name_is_label.color = background_text_color
        my_name_is_group.append(my_name_is_label)

        my_name_is_group2 = displayio.Group(scale=my_name_is_scale)
        my_name_is_label2 = Label(font=my_name_is_font,
                                  text=my_name_is_string2)
        (_, _, width, height) = my_name_is_label2.bounding_box
        my_name_is_label2.x = ((self.display.width // (2 * my_name_is_scale)) -
                               width // 2)
        my_name_is_label2.y = int(height // (0.32 * my_name_is_scale)) + 16
        my_name_is_label2.color = background_text_color
        my_name_is_group2.append(my_name_is_label2)

        # Main Body
        name_font_name = "/fonts/IdealSans-Semibold-48.bdf"
        name_font = bitmap_font.load_font(name_font_name)
        name_font.load_glyphs(name_string.encode('utf-8'))

        name_scale = name_scale
        name_group = displayio.Group(scale=name_scale)
        name_label = Label(font=name_font, text=name_string, line_spacing=0.75)
        (_, _, width, height) = name_label.bounding_box
        name_label.x = ((self.display.width // (2 * name_scale)) - width // 2)
        # name_label.y = int(height // (0.5 * name_scale))
        name_label.y = int((self.display.height // 2) + 25)
        name_label.color = foreground_text_color
        name_group.append(name_label)

        group = displayio.Group(max_size=5)
        group.append(splash)
        group.append(hello_group)
        group.append(my_name_is_group)
        group.append(my_name_is_group2)
        group.append(name_group)
        self.display.show(group)
Ejemplo n.º 13
0
    def show_badge(self,
                   *,
                   background_color=0xFF0000,
                   foreground_color=0xFFFFFF,
                   background_text_color=0xFFFFFF,
                   foreground_text_color=0x000000,
                   hello_font=terminalio.FONT,
                   hello_scale=1,
                   hello_string="HELLO",
                   my_name_is_font=terminalio.FONT,
                   my_name_is_scale=1,
                   my_name_is_string="MY NAME IS",
                   name_font=terminalio.FONT,
                   name_scale=1,
                   name_string="Blinka"):
        """Create a "Hello My Name is"-style badge.

        :param background_color: The color of the background. Defaults to 0xFF0000.
        :param foreground_color: The color of the foreground rectangle. Defaults to 0xFFFFFF.
        :param background_text_color: The color of the "HELLO MY NAME IS" text. Defaults to
                                      0xFFFFFF.
        :param foreground_text_color: The color of the name text. Defaults to 0x000000.
        :param hello_font: The font for the "HELLO" string. Defaults to ``terminalio.FONT``.
        :param hello_scale: The size scale of the "HELLO" string. Defaults to 1.
        :param hello_string: The first string of the badge. Defaults to "HELLO".
        :param my_name_is_font: The font for the "MY NAME IS" string. Defaults to
                                ``terminalio.FONT``.
        :param my_name_is_scale: The size scale of the "MY NAME IS" string. Defaults to 1.
        :param my_name_is_string: The second string of the badge. Defaults to "MY NAME IS".
        :param name_font: The font for the name string. Defaults to ``terminalio.FONT``.
        :param name_scale: The size scale of the name string. Defaults to 1.
        :param name_string: The third string of the badge - change to be your name. Defaults to
                            "Blinka".

        """
        splash = displayio.Group(max_size=20)

        color_bitmap = displayio.Bitmap(self.display.width,
                                        self.display.height, 1)
        color_palette = displayio.Palette(1)
        color_palette[0] = background_color

        bg_sprite = displayio.TileGrid(color_bitmap,
                                       pixel_shader=color_palette,
                                       x=0,
                                       y=0)
        splash.append(bg_sprite)

        rect = Rect(0, (int(self.display.height * 0.4)),
                    self.display.width, (int(self.display.height * 0.5)),
                    fill=foreground_color)
        splash.append(rect)

        hello_font_name = "/fonts/Verdana-Bold-18.bdf"
        hello_font = bitmap_font.load_font(hello_font_name)
        hello_font.load_glyphs(hello_string.encode('utf-8'))

        hello_scale = hello_scale
        hello_group = displayio.Group(scale=hello_scale)
        hello_label = Label(font=hello_font, text=hello_string)
        (_, _, width, height) = hello_label.bounding_box
        hello_label.x = ((self.display.width // (2 * hello_scale)) -
                         width // 2)
        hello_label.y = int(height // (1.2 * hello_scale))
        hello_label.color = background_text_color
        hello_group.append(hello_label)

        my_name_is_font_name = "/fonts/Arial-12.bdf"
        my_name_is_font = bitmap_font.load_font(my_name_is_font_name)
        my_name_is_font.load_glyphs(my_name_is_string.encode('utf-8'))

        my_name_is_scale = my_name_is_scale
        my_name_is_group = displayio.Group(scale=my_name_is_scale)
        my_name_is_label = Label(font=my_name_is_font, text=my_name_is_string)
        (_, _, width, height) = my_name_is_label.bounding_box
        my_name_is_label.x = ((self.display.width // (2 * my_name_is_scale)) -
                              width // 2)
        my_name_is_label.y = int(height // (0.32 * my_name_is_scale))
        my_name_is_label.color = background_text_color
        my_name_is_group.append(my_name_is_label)

        name_font_name = "/fonts/IdealSans-Semibold-48.bdf"
        name_font = bitmap_font.load_font(name_font_name)
        name_font.load_glyphs(name_string.encode('utf-8'))

        name_scale = name_scale
        name_group = displayio.Group(scale=name_scale)
        name_label = Label(font=name_font, text=name_string, line_spacing=0.75)
        (_, _, width, height) = name_label.bounding_box
        name_label.x = ((self.display.width // (2 * name_scale)) - width // 2)
        name_label.y = int(height // (0.45 * name_scale))
        name_label.color = foreground_text_color
        name_group.append(name_label)

        group = displayio.Group()
        group.append(splash)
        group.append(hello_group)
        group.append(my_name_is_group)
        group.append(name_group)
        self.display.show(group)
Ejemplo n.º 14
0
    def show_business_card(self,
                           *,
                           image_name=None,
                           name_string=None,
                           name_scale=1,
                           name_font=terminalio.FONT,
                           email_string_one=None,
                           email_scale_one=1,
                           email_font_one=terminalio.FONT,
                           email_string_two=None,
                           email_scale_two=1,
                           email_font_two=terminalio.FONT):
        """Display a bitmap image and a text string, such as a personal image and email address.

        :param str image_name: REQUIRED. The name of the bitmap image including .bmp, e.g.
                               ``"Blinka.bmp"``.
        :param str name_string: A name string to display along the bottom of the display, e.g.
                                 ``"Blinka"``.
        :param int name_scale: The scale of ``name_string``. Defaults to 1.
        :param name_font: The font for the name string. Defaults to ``terminalio.FONT``.
        :param str email_string_one: A string to display along the bottom of the display, e.g.
                                 ``"*****@*****.**"``.
        :param int email_scale_one: The scale of ``email_string_one``. Defaults to 1.
        :param email_font_one: The font for the first email string. Defaults to ``terminalio.FONT``.
        :param str email_string_two: A second string to display along the bottom of the display.
                                     Use if your email address is longer than one line or to add
                                     more space between the name and email address,
                                     e.g. (blinka@) ``"adafruit.com"``.
        :param int email_scale_two: The scale of ``email_string_two``. Defaults to 1.
        :param email_font_two: The font for the second email string. Defaults to
                               ``terminalio.FONT``.

        """
        business_card_splash = displayio.Group(max_size=30)
        self.display.show(business_card_splash)
        with open(image_name, "rb") as file_name:
            on_disk_bitmap = displayio.OnDiskBitmap(file_name)
            face_image = displayio.TileGrid(
                on_disk_bitmap, pixel_shader=displayio.ColorConverter())
            business_card_splash.append(face_image)
            # self.display.wait_for_frame()   #CP 4
            self.display.refresh()  #CP 5
        if name_string:
            name_group = displayio.Group(scale=name_scale)
            name_label = Label(name_font, text=name_string)
            (_, _, width, height) = name_label.bounding_box
            name_label.x = ((self.display.width // (2 * name_scale)) -
                            width // 2)
            name_label.y = int(height // (0.15 * name_scale))
            name_label.color = 0xFFFFFF
            name_group.append(name_label)
            business_card_splash.append(name_group)
        if email_string_one:
            email_group_one = displayio.Group(scale=email_scale_one)
            email_label_one = Label(email_font_one, text=email_string_one)
            (_, _, width, height) = email_label_one.bounding_box
            email_label_one.width = self.display.width
            email_label_one.x = ((self.display.width //
                                  (2 * email_scale_one)) - width // 2)
            email_label_one.y = int(height // (0.13 * email_scale_one))
            email_label_one.color = 0xFFFFFF
            email_group_one.append(email_label_one)
            business_card_splash.append(email_group_one)
        if email_string_two:
            email_group_two = displayio.Group(scale=email_scale_two)
            email_label_two = Label(email_font_two, text=email_string_two)
            (_, _, width, height) = email_label_two.bounding_box
            email_label_two.width = self.display.width
            email_label_two.x = ((self.display.width //
                                  (2 * email_scale_two)) - width // 2)
            email_label_two.y = int(height // (0.12 * email_scale_two))
            email_label_two.color = 0xFFFFFF
            email_group_two.append(email_label_two)
            business_card_splash.append(email_group_two)
Ejemplo n.º 15
0
                    default_bg="/tides_bg_graph.bmp")

# Connect to the internet and get local time
pyportal.get_local_time()

# Setup palette used for plot
palette = displayio.Palette(3)
palette[0] = 0x0
palette[1] = PLOT_COLOR
palette[2] = MARK_COLOR
palette.make_transparent(0)

# Setup tide plot bitmap
tide_plot = displayio.Bitmap(WIDTH, HEIGHT, 3)
pyportal.graphics.splash.append(
    displayio.TileGrid(tide_plot, pixel_shader=palette))

# Setup font used for date and time
date_font = bitmap_font.load_font("/fonts/mono-bold-8.bdf")
date_font.load_glyphs(b"1234567890-")

# Setup date label
date_label = Label(date_font, text="0000-00-00", color=DATE_COLOR, x=7, y=14)
pyportal.graphics.splash.append(date_label)

# Setup time label
time_label = Label(date_font, text="00:00:00", color=TIME_COLOR, x=234, y=14)
pyportal.graphics.splash.append(time_label)

# Setup current time marker
time_marker_bitmap = displayio.Bitmap(MARK_SIZE, MARK_SIZE, 3)
    def show_business_card(self,
                           *,
                           image_name=None,
                           name_string=None,
                           name_scale=1,
                           name_font=terminalio.FONT,
                           font_color=0xFFFFFF,
                           font_background_color=None,
                           email_string_one=None,
                           email_scale_one=1,
                           email_font_one=terminalio.FONT,
                           email_string_two=None,
                           email_scale_two=1,
                           email_font_two=terminalio.FONT):
        """Display a bitmap image and a text string, such as a personal image and email address.

        :param str image_name: REQUIRED. The name of the bitmap image including .bmp, e.g.
                               ``"Blinka.bmp"``.
        :param str name_string: A name string to display along the bottom of the display, e.g.
                                 ``"Blinka"``.
        :param int name_scale: The scale of ``name_string``. Defaults to 1.
        :param name_font: The font for the name string. Defaults to ``terminalio.FONT``.
        :param str email_string_one: A string to display along the bottom of the display, e.g.
                                 ``"*****@*****.**"``.
        :param int email_scale_one: The scale of ``email_string_one``. Defaults to 1.
        :param email_font_one: The font for the first email string. Defaults to ``terminalio.FONT``.
        :param str email_string_two: A second string to display along the bottom of the display.
                                     Use if your email address is longer than one line or to add
                                     more space between the name and email address,
                                     e.g. (blinka@) ``"adafruit.com"``.
        :param int email_scale_two: The scale of ``email_string_two``. Defaults to 1.
        :param email_font_two: The font for the second email string. Defaults to
                               ``terminalio.FONT``.

        .. code-block:: python

            from adafruit_pybadger import pybadger

            while True:
                pybadger.show_business_card(image_name="Blinka.bmp", name_string="Blinka",
                                            name_scale=2, email_string_one="blinka@",
                                            email_string_two="adafruit.com")

        """
        business_card_label_groups = []
        if name_string:
            name_group = self._create_label_group(
                text=name_string,
                font=name_font,
                color=font_color,
                scale=name_scale,
                height_adjustment=0.73,
                background_color=font_background_color,
            )
            business_card_label_groups.append(name_group)
        if email_string_one:
            email_one_group = self._create_label_group(
                text=email_string_one,
                font=email_font_one,
                color=font_color,
                scale=email_scale_one,
                height_adjustment=0.84,
                background_color=font_background_color,
            )
            business_card_label_groups.append(email_one_group)
        if email_string_two:
            email_two_group = self._create_label_group(
                text=email_string_two,
                font=email_font_two,
                color=font_color,
                scale=email_scale_two,
                height_adjustment=0.91,
                background_color=font_background_color,
            )
            business_card_label_groups.append(email_two_group)

        business_card_splash = displayio.Group()
        self.display.show(business_card_splash)
        with open(image_name, "rb") as file_name:
            on_disk_bitmap = displayio.OnDiskBitmap(file_name)
            face_image = displayio.TileGrid(
                on_disk_bitmap,
                pixel_shader=getattr(on_disk_bitmap, "pixel_shader",
                                     displayio.ColorConverter()),
                # TODO: Once CP6 is no longer supported, replace the above line with below
                # pixel_shader=on_disk_bitmap.pixel_shader,
            )
            business_card_splash.append(face_image)
            for group in business_card_label_groups:
                business_card_splash.append(group)

            self.display.refresh()
Ejemplo n.º 17
0
    font=FONT,
    text="Scan QR Code...",
    color=0xFFFFFF,
    background_color=0x0,
    padding_top=2,
    padding_left=2,
    padding_right=2,
    padding_bottom=2,
    anchor_point=(0.5, 1.0),
    anchored_position=(160, 230),
)
# Show the camera image at 2x size
g1 = displayio.Group(scale=2)
view = np.frombuffer(bitmap, dtype=np.uint8)
tg = displayio.TileGrid(
    bitmap,
    pixel_shader=pal,
)
tg.flip_y = True
g1.append(tg)
g = displayio.Group()
g.append(g1)
g.append(label)
display.show(g)
display.auto_refresh = False

old_payload = None
while True:
    cam.capture(bitmap)

    for row in qrdecoder.decode(bitmap, qrio.PixelPolicy.EVEN_BYTES):
        payload = row.payload
Ejemplo n.º 18
0
        label.Label(terminalio.FONT,
                    text="PM10: {:d}",
                    color=blue,
                    x=80,
                    y=5,
                    max_glyphs=15))
    # pms5003_splotter.group.append(label.Label(terminalio.FONT, text="PM1.0: {:d}", color=red, x=0, y=20, max_glyphs=15)) # uncomment to enable PM1.0 measuring

    # red line for the WHO guideline (https://en.wikipedia.org/wiki/Air_quality_guideline)
    # made in a new bitmap so it doesn't get overwritten
    pms5003_splotter.redline_bm = displayio.Bitmap(160, 1, 1)
    pms5003_splotter.redline_pl = displayio.Palette(1)
    pms5003_splotter.redline_pl[0] = red
    pms5003_splotter.redline_tg = displayio.TileGrid(
        pms5003_splotter.redline_bm,
        pixel_shader=pms5003_splotter.redline_pl,
        x=0,
        y=44)
    pms5003_splotter.group.append(pms5003_splotter.redline_tg)

# Set up the gas screen plotter
# the max value is set to 3.3 as its the max voltage the feather can read
gas_splotter = plotter.ScreenPlotter([red, green, blue],
                                     max_value=3.3,
                                     min_value=0.5,
                                     top_space=10,
                                     display=screen)

# add a colour coded text label for each reading
gas_splotter.group.append(
    label.Label(terminalio.FONT,
Ejemplo n.º 19
0
                 rowstart=80,
                 backlight_pin=tft_backlight,
                 rotation=180)

# Load background image
try:
    bg_bitmap, bg_palette = adafruit_imageload.load(BACKGROUND,
                                                    bitmap=displayio.Bitmap,
                                                    palette=displayio.Palette)
# Or just use solid color
except (OSError, TypeError):
    BACKGROUND = BACKGROUND if isinstance(BACKGROUND, int) else 0x000000
    bg_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)
    bg_palette = displayio.Palette(1)
    bg_palette[0] = BACKGROUND
background = displayio.TileGrid(bg_bitmap, pixel_shader=bg_palette)

# Shared palette for snow bitmaps
palette = displayio.Palette(2)
palette[0] = 0xADAF00  # transparent color
palette[1] = SNOW_COLOR  # snow color
palette.make_transparent(0)

# Snowflake setup
FLAKES = (
    0,
    0,
    0,
    0,
    0,
    0,
Ejemplo n.º 20
0
BORDER = 2

display = adafruit_displayio_sh1107.SH1107(display_bus,
                                           width=WIDTH,
                                           height=HEIGHT)

# Make the display context
splash = displayio.Group()
display.show(splash)

color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFFFFFF  # White

bg_sprite = displayio.TileGrid(color_bitmap,
                               pixel_shader=color_palette,
                               x=0,
                               y=0)
splash.append(bg_sprite)

# Draw a smaller inner rectangle in black
inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0x000000  # Black
inner_sprite = displayio.TileGrid(inner_bitmap,
                                  pixel_shader=inner_palette,
                                  x=BORDER,
                                  y=BORDER)
splash.append(inner_sprite)

# Draw some white squares
sm_bitmap = displayio.Bitmap(8, 8, 1)
def update_display():
    # pylint: disable=too-many-locals
    # clear out existing icons
    while len(storm_icons):
        _ = storm_icons.pop()

    # get latest storm data
    try:
        resp = pyportal.network.fetch(URL)
        storm_data = pyportal.network.process_json(resp.json(),
                                                   (JSON_PATH, ))[0]
    except RuntimeError:
        return
    print("Number of storms:", len(storm_data))

    # parse the storm data
    for storm in storm_data:
        # don't exceed max
        if len(storm_icons) >= MAX_STORMS:
            continue
        # get lat/lon
        lat = storm["latitudeNumeric"]
        lon = storm["longitudeNumeric"]
        # check if on map
        if (not LAT_RANGE[0] >= lat >= LAT_RANGE[1]
                or not LON_RANGE[0] <= lon <= LON_RANGE[1]):
            continue
        # OK, let's make a group for all the graphics
        storm_gfx = displayio.Group()
        # convert to sreen coords
        x = int(
            map_range(lon, LON_RANGE[0], LON_RANGE[1], 0,
                      board.DISPLAY.width - 1))
        y = math.radians(lat)
        y = math.tan(math.pi / 4 + y / 2)
        y = math.log(y)
        y = (VIRTUAL_WIDTH * y) / (2 * math.pi)
        y = VIRTUAL_HEIGHT / 2 - y
        y = int(y - Y_OFFSET)
        # icon type
        if storm["classification"] in STORM_CLASS:
            storm_type = STORM_CLASS.index(storm["classification"])
        else:
            storm_type = 0
        # create storm icon
        icon = displayio.TileGrid(
            icons_bmp,
            pixel_shader=icons_pal,
            width=1,
            height=1,
            tile_width=16,
            tile_height=16,
            default_tile=storm_type,
            x=x - 8,
            y=y - 8,
        )
        # add storm icon
        storm_gfx.append(icon)
        # add a label
        name = Label(
            terminalio.FONT,
            text=storm["name"],
            color=NAME_COLOR,
            background_color=NAME_BG_COLOR,
        )
        name.anchor_point = (0.0, 1.0)
        name.anchored_position = (x + 8, y - 8)
        storm_gfx.append(name)
        # add direction arrow
        angle = math.radians(storm["movementDir"])
        xd = x + int(ARROW_LENGTH * math.sin(angle))
        yd = y - int(ARROW_LENGTH * math.cos(angle))
        arrow = Line(x, y, xd, yd, color=ARROW_COLOR)
        storm_gfx.append(arrow)
        # add the storm graphics
        storm_icons.append(storm_gfx)
        # update time
        info_update.text = storm["lastUpdate"]
        # debug
        print("{} @ {},{}".format(storm["name"], storm["latitudeNumeric"],
                                  storm["longitudeNumeric"]))

    # no storms? at least say something
    if not len(storm_icons):
        print("No storms in map area.")
        storm_icons.append(
            Label(
                terminalio.FONT,
                scale=4,
                x=50,
                y=110,
                text="NO STORMS\n IN AREA",
                color=NAME_COLOR,
                background_color=NAME_BG_COLOR,
            ))
Ejemplo n.º 22
0
                                                palette=displayio.Palette)

display = board.DISPLAY
group = displayio.Group(scale=1, max_size=5)
touchscreen = adafruit_touchscreen.Touchscreen(board.TOUCH_XL,
                                               board.TOUCH_XR,
                                               board.TOUCH_YD,
                                               board.TOUCH_YU,
                                               calibration=((9000, 59000),
                                                            (8000, 57000)),
                                               size=(display.width,
                                                     display.height))
tilegrid = displayio.TileGrid(sprite_sheet,
                              pixel_shader=palette,
                              width=20,
                              height=15,
                              tile_height=16,
                              tile_width=16,
                              default_tile=BLANK)
group.append(tilegrid)

display.show(group)

board_data = bytearray(b'\x00' * 300)


#pylint:disable=redefined-outer-name
def get_data(x, y):
    return board_data[y * 20 + x]

import board
import displayio

display = board.DISPLAY

# Create a bitmap with two colors
bitmap = displayio.Bitmap(display.width, display.height, 2)

# Create a two color palette
palette = displayio.Palette(2)
palette[0] = 0x000000
palette[1] = 0xffffff

# Create a TileGrid using the Bitmap and Palette
tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)

# Create a Group
group = displayio.Group()

# Add the TileGrid to the Group
group.append(tile_grid)

# Add the Group to the Display
display.show(group)

# Draw a pixel
bitmap[80, 50] = 1

# Draw even more pixels
for x in range(150, 170):
    for y in range(100, 110):
    0xFF96FF,  # pink
)
MESSAGE_COLORS = (
    0xFF0000,  # red
)
#---| User Config |--------------------------------------------------

# Create the display
display = board.DISPLAY

# Load the candy heart BMP
bitmap, palette = adafruit_imageload.load("/heart_bw.bmp",
                                          bitmap=displayio.Bitmap,
                                          palette=displayio.Palette)

heart = displayio.TileGrid(bitmap, pixel_shader=palette)

# Set up message text
font = bitmap_font.load_font("/Multicolore_36.bdf")
line1 = label.Label(font, text="?" * 9)
line2 = label.Label(font, text="?" * 5)
line1.anchor_point = (0.5, 0)  # middle top
line2.anchor_point = (0.5, 1.0)  # middle bottom

# Set up group and add to display
group = displayio.Group()
group.append(heart)
group.append(line1)
group.append(line2)
display.show(group)
                                      board.TOUCH_YD,
                                      board.TOUCH_YU,
                                      calibration=((5200, 59000), (5800,
                                                                   57000)),
                                      size=(SCREEN_WIDTH, SCREEN_HEIGHT))

# Make the display context
calc_group = displayio.Group(max_size=25)
board.DISPLAY.show(calc_group)

# Make a background color fill
color_bitmap = displayio.Bitmap(SCREEN_WIDTH, SCREEN_HEIGHT, 1)
color_palette = displayio.Palette(1)
color_palette[0] = GRAY
bg_sprite = displayio.TileGrid(color_bitmap,
                               pixel_shader=color_palette,
                               x=0,
                               y=0)
calc_group.append(bg_sprite)

# Load the font
if SCREEN_WIDTH < 480:
    font = bitmap_font.load_font("/fonts/Arial-12.bdf")
else:
    font = bitmap_font.load_font("/fonts/Arial-Bold-24.bdf")

buttons = []


# Some button functions
def button_grid(row, col):
    return Coords(BUTTON_MARGIN * (row + 1) + BUTTON_WIDTH * row + 20,
Ejemplo n.º 26
0
WIDTH = board.DISPLAY.width
HEIGHT = board.DISPLAY.height

pyportal = PyPortal()

palette = displayio.Palette(5)
palette[0] = 0x0
palette[1] = PROFILE_COLOR
palette[2] = GRID_COLOR
palette[3] = TEMP_COLOR
palette[4] = AXIS_COLOR
palette.make_transparent(0)

plot = displayio.Bitmap(WIDTH, HEIGHT, 8)
pyportal.splash.append(displayio.TileGrid(plot, pixel_shader=palette))

ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL,
                                      board.TOUCH_XR,
                                      board.TOUCH_YD,
                                      board.TOUCH_YU,
                                      calibration=((5200, 59000), (5800,
                                                                   57000)),
                                      size=(WIDTH, HEIGHT))


class Beep(object):
    def __init__(self):
        self.duration = 0
        self.start = 0
        tone_volume = 1  # volume is from 0.0 to 1.0
Ejemplo n.º 27
0
import time
import displayio
from adafruit_gizmo import eink_gizmo

display = eink_gizmo.EInk_Gizmo()

# Create a display group for our screen objects
display_group = displayio.Group()

# Display a ruler graphic from the root directory of the CIRCUITPY drive
file = open("/display-ruler.bmp", "rb")

picture = displayio.OnDiskBitmap(file)
# Create a Tilegrid with the bitmap and put in the displayio group
sprite = displayio.TileGrid(picture, pixel_shader=displayio.ColorConverter())
display_group.append(sprite)

# Place the display group on the screen
display.show(display_group)

# Refresh the display to have it actually show the image
# NOTE: Do not refresh eInk displays sooner than 180 seconds
display.refresh()
print("refreshed")

time.sleep(180)
Ejemplo n.º 28
0
left_group.y = (SCREEN_SIZE - IMAGE_SIZE) // 2

right_group.x = (SCREEN_SIZE - IMAGE_SIZE) // 2
right_group.y = (SCREEN_SIZE - IMAGE_SIZE) // 2

#  load in party parrot bitmap
star_bitmap, star_palette = adafruit_imageload.load("/rainbow_star.bmp",
                                                    bitmap=displayio.Bitmap,
                                                    palette=displayio.Palette)

right_star_grid = displayio.TileGrid(
    star_bitmap,
    pixel_shader=star_palette,
    width=1,
    height=1,
    tile_height=64,
    tile_width=64,
    default_tile=0,
    x=0,
    y=0,
)

left_star_grid = displayio.TileGrid(
    star_bitmap,
    pixel_shader=star_palette,
    width=1,
    height=1,
    tile_height=64,
    tile_width=64,
    default_tile=0,
    x=0,
Ejemplo n.º 29
0
spi = busio.SPI(clock=spi_clk, MOSI=spi_mosi, MISO=spi_miso)

display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = adafruit_ili9341.ILI9341(display_bus, width=WIDTH, height=HEIGHT)

# Initially, just show a bright green background to prove the display is working
splash = displayio.Group(max_size=10)
display.show(splash)

color_bitmap = displayio.Bitmap(320, 240, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0x00FF00  # Bright Green

bg_sprite = displayio.TileGrid(color_bitmap,
                               pixel_shader=color_palette,
                               x=0,
                               y=0)

splash.append(bg_sprite)

# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(280, 200, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0xAA0088  # Purple
inner_sprite = displayio.TileGrid(inner_bitmap,
                                  pixel_shader=inner_palette,
                                  x=20,
                                  y=20)
splash.append(inner_sprite)

# Wait so it doesn't immediately get overwritten
Ejemplo n.º 30
0
display = board.DISPLAY

#  the alarm sound file locations
alarm_sound_trash = "/sounds/trash.wav"
alarm_sound_bed = "/sounds/sleep.wav"
alarm_sound_eat = "/sounds/eat.wav"

#  the alarm sounds in an array that matches the order of the gfx & alarm check-ins
alarm_sounds = [alarm_sound_trash, alarm_sound_bed,
                alarm_sound_eat, alarm_sound_eat, alarm_sound_eat]

#  setting up the bitmaps for the alarms

#  sleep alarm
sleep_bitmap = displayio.OnDiskBitmap(open("/sleepBMP.bmp", "rb"))
sleep_tilegrid = displayio.TileGrid(sleep_bitmap, pixel_shader=getattr(sleep_bitmap, 'pixel_shader', displayio.ColorConverter()))
group_bed = displayio.Group()
group_bed.append(sleep_tilegrid)

#  trash alarm
trash_bitmap = displayio.OnDiskBitmap(open("/trashBMP.bmp", "rb"))
trash_tilegrid = displayio.TileGrid(trash_bitmap, pixel_shader=getattr(trash_bitmap, 'pixel_shader', displayio.ColorConverter()))
group_trash = displayio.Group()
group_trash.append(trash_tilegrid)

#  meal alarm
eat_bitmap = displayio.OnDiskBitmap(open("/eatBMP.bmp", "rb"))
eat_tilegrid = displayio.TileGrid(eat_bitmap, pixel_shader=getattr(eat_bitmap, 'pixel_shader', displayio.ColorConverter()))
group_eat = displayio.Group()
group_eat.append(eat_tilegrid)