def draw_grid_at_position(position): ## Clear all samples at this X position. display.vline(position, 0, DISPLAY_PX, color565(0, 0, 0)) ## Draw white points at this X position ## to re-create the temperature scale for value in temp_grid: y = f_to_px(value) display.pixel(position, y, color565(255, 255, 255))
def draw_temps_graph(position, data): draw_grid_at_position(position) for idx, value in enumerate(data): y = f_to_px(c_to_f(value)) dy = abs(y - last_px[idx]) color = color565(*COLORMAP[idx]) if dy > 1: ypos = min(y, last_px[idx]) display.vline(position, ypos, dy, color) else: display.pixel(position, y, color) last_px[idx] = y
def __init__(self, upside_down=False, name='screen'): cs_pin = digitalio.DigitalInOut(board.CE0) dc_pin = digitalio.DigitalInOut(board.D24) reset_pin = digitalio.DigitalInOut(board.D25) BAUDRATE = 40000000 spi = board.SPI() self.name = name self.active = False rotation_angle = 90 if not upside_down else 270 self.disp = st7735.ST7735R(spi, rotation=rotation_angle, cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE) self.bgcolor = color565(0, 0, 0) self.led = LED(config.screen_led_pin, initial_value=True) # --- swap width/height, if if self.disp.rotation % 180 == 90: height, width = self.disp.width, self.disp.height else: width, height = self.disp.width, self.disp.height self.width, self.height = width, height logger.debug(F" ---> disp {self.disp.width},{self.disp.height}") self.boldfont = ImageFont.truetype(pkg_resources.resource_filename("timemachine.fonts", "DejaVuSansMono-Bold.ttf"), 33) self.boldsmall = ImageFont.truetype(pkg_resources.resource_filename("timemachine.fonts", "DejaVuSansMono-Bold.ttf"), 22) self.font = ImageFont.truetype(pkg_resources.resource_filename("timemachine.fonts", "ariallgt.ttf"), 30) self.smallfont = ImageFont.truetype(pkg_resources.resource_filename("timemachine.fonts", "ariallgt.ttf"), 20) self.oldfont = ImageFont.truetype(pkg_resources.resource_filename("timemachine.fonts", "FreeMono.ttf"), 20) self.largefont = ImageFont.truetype(pkg_resources.resource_filename("timemachine.fonts", "FreeMono.ttf"), 30) self.hugefont = ImageFont.truetype(pkg_resources.resource_filename("timemachine.fonts", "FreeMono.ttf"), 40) self.image = Image.new("RGB", (width, height)) self.draw = ImageDraw.Draw(self.image) # draw using this object. Display image when complete. self.staged_date = None self.selected_date = None self.staged_date_bbox = Bbox(0, 0, 160, 31) # self.selected_date_bbox = Bbox(0,100,130,128) self.selected_date_bbox = Bbox(0, 100, 160, 128) self.venue_bbox = Bbox(0, 31, 160, 56) self.nevents_bbox = Bbox(148, 31, 160, 56) self.track1_bbox = Bbox(0, 55, 160, 77) self.track2_bbox = Bbox(0, 78, 160, 100) self.playstate_bbox = Bbox(130, 100, 160, 128) self.sbd_bbox = Bbox(155, 100, 160, 108) self.exp_bbox = Bbox(0, 55, 160, 100) self.update_now = True self.sleeping = False
import time import busio import digitalio from board import SCK, MOSI, MISO, CE0, CE1 from adafruit_rgb_display import color565 import adafruit_rgb_display.ili9341 as ili9341 # Configuration for CS and DC pins: CS_PIN = D2 DC_PIN = D3 # Setup SPI bus using hardware SPI: spi = busio.SPI(clock=SCK, MOSI=MOSI, MISO=MISO) # Create the ILI9341 display: disp = hx8357.HX8357(spi, rotation=180, disp = hx8357.HX8357(spi, rotation=90, cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE) while True: display.fill(0) display.pixel(120, 160, color565(255, 0, 0)) time.sleep(2) display.fill(color565(0, 0, 255)) time.sleep(2)
import board import digitalio import adafruit_stmpe610 from adafruit_rgb_display import ili9341, color565 # Create library object using our Bus SPI port spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO) # Adafruit Metro M0 + 2.8" Capacitive touch shield cs_pin = digitalio.DigitalInOut(board.D9) dc_pin = digitalio.DigitalInOut(board.D10) # Initialize display display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin) # Fill with black! display.fill(color565(0, 0, 0)) st_cs_pin = digitalio.DigitalInOut(board.D6) st = adafruit_stmpe610.Adafruit_STMPE610_SPI(spi, st_cs_pin) while True: if st.touched: while not st.buffer_empty: ts = st.touches for point in ts: # perform transformation to get into display coordinate system! y = point["y"] x = 4096 - point["x"] x = 2 * x // 30 y = 8 * y // 90 display.fill_rectangle(x - 2, y - 2, 4, 4, color565(255, 0, 0))
import board import busio from digitalio import DigitalInOut from adafruit_rgb_display import color565 import adafruit_rgb_display.ili9341 as ili9341 spi = busio.SPI(clock=board.P1_10, MOSI=board.P1_13) dc_pin = DigitalInOut(board.P0_02) # any pin! reset_pin = DigitalInOut(board.P1_15) # any pin! cs_pin = DigitalInOut(board.P0_29) # any pin! display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin, rst=reset_pin) display.fill(color565(255, 0, 0)) display.pixel(64, 64, 0)
import digitalio from adafruit_rgb_display import ili9341, color565 import tsc2004 # Create a SPI bus object for the display spi = board.SPI() # Keyboard FeatherWing default pins tft_cs = digitalio.DigitalInOut(board.D9) tft_dc = digitalio.DigitalInOut(board.D10) # Initialize display display = ili9341.ILI9341(spi, cs=tft_cs, dc=tft_dc) # Fill with black! display.fill(color565(0, 0, 0)) # Create a I2C bus object for the touch driver i2c = board.I2C() # Create the touch driver object tsc = tsc2004.TSC2004(i2c) TS_MINX = 260 TS_MAXX = 4800 TS_MINY = 300 TS_MAXY = 2900 # This function help transforming the touch coordinate system to the display coordinates def _map(x, in_min, in_max, out_min, out_max): return int((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min)
import busio import board import digitalio import adafruit_focaltouch from adafruit_rgb_display import ili9341, color565 # Create library object using our Bus I2C & SPI port i2c = busio.I2C(board.SCL, board.SDA) spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO) # Adafruit Metro M0 + 2.8" Capacitive touch shield cs_pin = digitalio.DigitalInOut(board.D10) dc_pin = digitalio.DigitalInOut(board.D9) # Initialize display display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin) # Fill with black! display.fill(color565(0, 0, 0)) ft = adafruit_focaltouch.Adafruit_FocalTouch(i2c) while True: if ft.touched: ts = ft.touches point = ts[0] # the shield only supports one point! # perform transformation to get into display coordinate system! y = 320 - point['y'] x = 240 - point['x'] display.fill_rectangle(x-2, y-2, 4, 4, color565(255, 255, 255))
def get_color(): rgb = (color["Red"], color["Green"], color["Blue"]) return color565(*rgb)
import time import busio import digitalio from board import SCK, MOSI, MISO, D2, D3 from adafruit_rgb_display import color565 import adafruit_rgb_display.ili9341 as ili9341 # Configuration for CS and DC pins: CS_PIN = D2 DC_PIN = D3 # Setup SPI bus using hardware SPI: spi = busio.SPI(clock=SCK, MOSI=MOSI, MISO=MISO) # Create the ILI9341 display: display = ili9341.ILI9341(spi, cs=digitalio.DigitalInOut(CS_PIN), dc=digitalio.DigitalInOut(DC_PIN)) # Main loop: while True: # Clear the display display.fill(0) # Draw a red pixel in the center. display.pixel(120, 160, color565(255, 0, 0)) # Pause 2 seconds. time.sleep(2) # Clear the screen blue. display.fill(color565
from adafruit_rgb_display import color565 import adafruit_rgb_display.ili9341 as ili9341 # Configuratoin for CS and DC pins (these are FeatherWing defaults on ESP8266): CS_PIN = GPIO0 DC_PIN = GPIO15 # Config for display baudrate (default is 32mhz, about as fast as the ESP supports): BAUDRATE = 32000000 # Setup SPI bus using hardware SPI: spi = busio.SPI(clock=SCK, MOSI=MOSI, MISO=MISO) # Create the ILI9341 display: display = ili9341.ILI9341(spi, cs=digitalio.DigitalInOut(CS_PIN), dc=digitalio.DigitalInOut(DC_PIN), baudrate=BAUDRATE) # Main loop: while True: # Clear the display display.fill(0) # Draw a red pixel in the center. display.pixel(120, 160, color565(255, 0, 0)) # Pause 2 seconds. time.sleep(2) # Clear the screen blue. display.fill(color565(0, 0, 255)) # Pause 2 seconds. time.sleep(2)
# with open('CityNames.txt', 'r') as f: # Cities = f.readlines() # with open('MaleFirstNames.txt', 'r') as f: # MaleFNames = f.readlines() # with open('FemaleFirstNames.txt', 'r') as f: # FemaleFNames = f.readlines() # with open('ShtLastNames.txt','r') as f: # LNames = f.readlines() display.fill(0) bf.text('Ready?!', 0, 0, color565(255, 255, 255)) while True: if not GoButton.value: display.fill(color565(255, 0, 0)) RndNum = (random.randint(100000000, 999999994)) RndNumStr = (str(RndNum)) print(RndNum) # Sort out the Occupation OccNumStr = (RndNumStr[6:8]) OccNumInt = (int(OccNumStr)) OccNumInt = Rounder(OccNumInt, 50) OccNumStr = str(OccNumInt)
if dy > 1: ypos = min(y, last_px[idx]) display.vline(position, ypos, dy, color) else: display.pixel(position, y, color) last_px[idx] = y gc.collect() ## Draw horizontal lines as a temperature scale for value in temp_grid: y = f_to_px(value) display.hline(0, y, DISPLAY_PX, color565(255, 255, 255)) ## Start on the left side of the screen position = DISPLAY_PX ## Advance to the next PX position, read temperature data, draw it while True: position -= 1 data = [sensor.temperature for sensor in sensors] draw_temps_graph(position, data) ## We're at the end of the display, go back to the left side if position <= 0: position = DISPLAY_PX
DC_PIN = board.D25 reset_pin = None BAUDRATE = 6400000 spi = board.SPI() display = driver.ST7789(spi, cs=digitalio.DigitalInOut(CS_PIN), dc=digitalio.DigitalInOut(DC_PIN), rst=reset_pin, baudrate=BAUDRATE, width=240, height=240, x_offset=0, y_offset=80) green = color565(0, 0, 255) #display.pixel(120,120,green) #for i in range(0,200): # for j in range(0,200): # display.pixel(i,j,green) slider = 0 foward = True while True: time.sleep(0.03) if (slider == 255): forward = False if (slider == 0): forward = True display.fill(color565(255 - slider, slider, 0)) slider = slider + 1 if forward else slider - 1
# cs = digitalio.DigitalInOut(board.GPIO0) # dc = digitalio.DigitalInOut(board.GPIO15) # For the Feather M0s cs = digitalio.DigitalInOut(board.D9) dc = digitalio.DigitalInOut(board.D10) display = ili9341.ILI9341(spi, cs=cs, dc=dc) # Initialize the GFX library, giving it the display pixel function as its pixel # drawing primitive command. The hline and vline parameters specify optional # optimized horizontal and vertical line drawing functions. You can remove these # to see how much slower the filled shape functions perform! graphics = gfx.GFX(240, 320, display.pixel, hline=fast_hline, vline=fast_vline) display.fill(0) # Clear the display graphics.line(0, 0, 239, 319, color565(255, 0, 0)) # Now loop forever drawing random lines. display.fill(0) while True: x0 = randrange(0, 240) y0 = randrange(0, 320) x1 = randrange(0, 240) y1 = randrange(0, 320) r = randrange(0, 255) g = randrange(0, 255) b = randrange(0, 255) graphics.line(x0, y0, x1, y1, color565(r, g, b)) time.sleep(0.01)