Created
July 20, 2022 01:16
-
-
Save FoamyGuy/fcb102aab7a598c19aae4843cc342231 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import busio | |
import board | |
import adafruit_focaltouch | |
import displayio | |
import dotclockdisplay | |
import framebufferio | |
from rainbowio import colorwheel | |
import adafruit_imageload | |
import vectorio | |
import rainbowio | |
box_size = 50 | |
corner_box_size = 20 | |
displayio.release_displays() | |
SCL_pin = board.IO41 # set to a pin that you want to use for SCL | |
SDA_pin = board.IO42 # set to a pin that you want to use for SDA | |
IRQ_pin = board.IO40 # select a pin to connect to the display's interrupt pin ("IRQ") | |
i2c = busio.I2C(SCL_pin, SDA_pin) | |
ft = adafruit_focaltouch.Adafruit_FocalTouch(i2c, debug=False) | |
time.sleep(6) | |
print(f"ft.chip: {ft.chip}") | |
datapin_list = [ | |
board.IO3, board.IO4, board.IO5, board.IO6, | |
board.IO7, board.IO8, board.IO9, board.IO10, | |
board.IO11, board.IO12, board.IO13, board.IO14, | |
board.IO15, board.IO16, board.IO17, board.IO18, | |
] | |
fb = dotclockdisplay.DotClockFramebuffer( | |
width=800, height=480, | |
hsync=board.IO47, vsync=board.IO48, | |
de=board.IO45, | |
pclock=board.IO21, | |
data_pins=datapin_list, | |
pclock_frequency=24 * 1000 * 1000, | |
hsync_back_porch=100, # 100 | |
hsync_front_porch=40, | |
hsync_pulse_width=5, | |
vsync_back_porch=25, | |
vsync_front_porch=10, | |
vsync_pulse_width=1, | |
pclock_active_neg=1, | |
bounce_buffer_size_px=1000 * 15, | |
) | |
print('Finished creating DotClockFrameBuffer.') | |
print('Creating DotClockFrameBuffer...') | |
display = framebufferio.FramebufferDisplay(fb) | |
main_group = displayio.Group() | |
bg_color = displayio.Palette(1) | |
bg_color[0] = 0xffffff | |
bg_rect = vectorio.Rectangle(pixel_shader=bg_color, width=display.width, height=display.height) | |
main_group.append(bg_rect) | |
#colors = [rainbowio.colorwheel(i) for i in range(0, 256, 256//5)] | |
colors = [0xff0000, 0xffff00, 0x00ff00, 0x00ffff, 0x0000ff, 0xff00ff] | |
# for color in colors: | |
# print(hex(color)) | |
palettes = [] | |
touch_circles = [] | |
touch_circle_groups = [] | |
for i in range(6): | |
_new_palette = displayio.Palette(1) | |
_new_palette[0] = colors[i] | |
palettes.append(_new_palette) | |
touch_circles.append(vectorio.Circle(pixel_shader=_new_palette, radius=70, x=-100, y=-100)) | |
touch_circle_groups.append(displayio.Group()) | |
touch_circle_groups[-1].append(touch_circles[-1]) | |
main_group.append(touch_circle_groups[-1]) | |
#main_group.append(touch_circles[-1]) | |
display.show(main_group) | |
# display.refresh(target_frames_per_second=60, minimum_frames_per_second=30) | |
#print("") | |
dont_hide_list = [] | |
while True: | |
if ft.touched: | |
ts = ft.touches | |
if ts != []: | |
print(ts) | |
for touch in ts: | |
try: | |
touch_circle_groups[touch["id"]].hidden = False | |
touch_circles[touch["id"]].x = touch["x"] | |
touch_circles[touch["id"]].y = touch["y"] | |
dont_hide_list.append(touch["id"]) | |
except IndexError: | |
pass | |
#print(ts) | |
for i in range(6): | |
if i not in dont_hide_list: | |
touch_circle_groups[i].hidden = True | |
while dont_hide_list: | |
dont_hide_list.pop() | |
# print(point) | |
time.sleep(0.0001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment