def init(i2c): global display, is_initialized, splash displayio.release_displays() display_bus = displayio.I2CDisplay(i2c, device_address=0x3c) WIDTH = 128 HEIGHT = 32 display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=WIDTH, height=HEIGHT) splash = displayio.Group(max_size=10) display.show(splash) color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1) color_palette = displayio.Palette(1) color_palette[0] = 0x000000 # White bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) splash.append(bg_sprite) text = " " text_area = label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=0, y=3) splash.append(text_area) text_area = label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=0, y=13) splash.append(text_area) text_area = label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=0, y=23) splash.append(text_area) is_initialized = True
def _init_stuff(self): # decouple display self.state_display_timeout = 1.0 self.state_display_start = 0 displayio.release_displays() i2c = board.I2C() display_bus = displayio.I2CDisplay(i2c, device_address=0x3D) self.display = adafruit_displayio_ssd1306.SSD1306( display_bus, width=DISPLAY_WIDTH, height=DISPLAY_HEIGHT) self.min_press_str = "min: %d" % self.min_pressure self.high_press_str = "hi: %d" % self.high_pressure self.pressure_sensor = adafruit_lps35hw.LPS35HW(i2c) self.pressure_sensor.zero_pressure() self.pressure_sensor.data_rate = adafruit_lps35hw.DataRate.RATE_75_HZ self.pressure_sensor.filter_enabled = True self.pressure_sensor.filter_config = True
def SetupDisplay(): # So we can communicate with our OLED via I2C i2c = busio.I2C(scl=board.GP3, sda=board.GP2) #while not i2c.try_lock(): # pass #print("i2c address is = ",i2c.scan()) # How displayio talks to physical screen display_bus = displayio.I2CDisplay( i2c, device_address=60) # was 0x3A, reset=oled_reset) # display represents the physical screen display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=WIDTH, height=HEIGHT, auto_refresh=False) # Group is a list of TileGrids that display would render on physical screen group = displayio.Group(max_size=1) display.show(group) return (display, group)
# midi setup print(usb_midi.ports) midi = adafruit_midi.MIDI( midi_in=usb_midi.ports[0], in_channel=0, midi_out=usb_midi.ports[1], out_channel=0 ) msg = midi.receive() # display width and height setup WIDTH = 128 HEIGHT = 64 BORDER = 5 # display setup display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=WIDTH, height=HEIGHT) splash = displayio.Group() display.show(splash) # text area setup text = "MIDI Messages" text_area = label.Label( terminalio.FONT, text=text, color=0xFFFFFF, x=30, y=HEIGHT // 2+1) splash.append(text_area) while True: # receive midi messages msg = midi.receive() if msg is not None:
""" This test will initialize the display using displayio and draw a solid white background, a smaller black rectangle, and some white text. """ import board import displayio import terminalio from adafruit_display_text import label import adafruit_displayio_ssd1306 displayio.release_displays() i2c = board.I2C() display_bus = displayio.I2CDisplay(i2c, device_address=0x3C) display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32) # Make the display context splash = displayio.Group(max_size=10) display.show(splash) color_bitmap = displayio.Bitmap(128, 32, 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)
oled_reset_right = board.D12 oled_cs_right = board.D13 oled_dc_right = board.D11 display_bus_right = displayio.FourWire(spi, command=oled_dc_right, chip_select=oled_cs_right, reset=oled_reset_right, baudrate=1000000) WIDTH = 128 HEIGHT = 64 BORDER = 5 display_left = adafruit_displayio_ssd1306.SSD1306(display_bus_left, width=WIDTH, height=HEIGHT) display_right = adafruit_displayio_ssd1306.SSD1306(display_bus_right, width=WIDTH, height=HEIGHT) group_left = displayio.Group(scale=2) group_right = displayio.Group(scale=2) group_left.y = 5 group_right.y = 5 display_left.show(group_left) display_right.show(group_right) name = ("/idle.bmp") odb, palette = adafruit_imageload.load(name, bitmap=displayio.Bitmap,
def __init__(self, bitmap): #imported bitmap displayio.release_displays() oled_reset = board.D9 #defines display; change device address/width/height if needed i2c = board.I2C() display_bus = displayio.I2CDisplay(i2c, device_address=0x3D, reset=oled_reset) self.display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=64) #imports sprite sheet, this should contain all sprites, you'll parse them later self.sprite_sheet, palette = adafruit_imageload.load( bitmap, bitmap=displayio.Bitmap, palette=displayio.Palette) #making individual tilemaps from main sprite sheet self.words = displayio.TileGrid( self.sprite_sheet, pixel_shader=palette, width=35, height=1, tile_width=1, tile_height=5 ) #width and height are of the tilegrid: tile_width and tile_height are the number of pixels of the bitmap self.background = displayio.TileGrid(self.sprite_sheet, pixel_shader=palette, width=8, height=4, tile_width=16, tile_height=16) self.sprite = displayio.TileGrid(self.sprite_sheet, pixel_shader=palette, width=1, height=1, tile_width=3, tile_height=3) self.highscore = displayio.TileGrid(self.sprite_sheet, pixel_shader=palette, width=60, height=1, tile_width=1, tile_height=5) #sub groups self.words_group = displayio.Group( scale=3 ) #creates subgroups; the scale value, suprisingly, changes the scale of the tilegrid self.words_group.x = 11 #position of subgroup in relation to main group self.words_group.y = 24 self.background_group = displayio.Group(scale=1) self.background_group.x = 0 self.background_group.y = 0 self.sprite_group = displayio.Group(scale=1) self.highscore_group = displayio.Group(scale=2) self.highscore_group.x = 4 self.highscore_group.y = 27 #main group self.group = displayio.Group() #creates main group