class Display: lock = _thread.allocate_lock() def __init__(self): self.alive = False self.Led = Pixel() self.tem = [[0, 0, 0]] * 25 # 显示缓存区m= def stop(self): self.alive = False if Display.lock.acquire(): # print("stop") Display.lock.release() def scroll(self, val, color=Red, delay=150): self.stop() self.alive = True if Display.lock.acquire(): # print("start") _thread.start_new_thread(self._scroll, ([val, color, delay])) Display.lock.release() def Disrupt_Col(color): a = color[-1] while True: if color_num != 1: import random random.shuffle(color) if a != color[0]: break def _scroll(self, val, color=Red, delay=150): pixel_col = [[0, 0, 0]] * 25 # 显示缓存区m= val = str(val) + ' ' color_num = 1 if color != Red: if isinstance(color[0], list): color_num = len(color) # self.Disrupt_Col(color) #打乱颜色顺序 col_cnt = 0 it = iter(color) for val1 in val: val2 = CharData[val1] if color_num == 1: now_col = color else: if col_cnt < color_num: now_col = next(it) # 确定当前字符的颜色 else: col_cnt = 0 it = iter(color) now_col = next(it) col_cnt += 1 for i in range(25): # 为字符的像素点添加颜色 if val2[i] == 1: pixel_col[i] = now_col else: pixel_col[i] = [0, 0, 0] if Display.lock.acquire(): for i in range(6): # 开始滚动显示 if self.alive == False: Display.lock.release() self.clear() _thread.exit() else: for t in range(4): self.tem[20 - (t * 5):20 - (t * 5) + 5] = self.tem[20 - ((t + 1) * 5):20 - ((t + 1) * 5) + 5] # 数据向前移动5位 if i == 5: self.tem[0:5] = Zero[0:5] # 每个字符之间间隔一行 else: self.tem[0:5] = pixel_col[20 - (i * 5):20 - (i * 5) + 5] for r in range(25): self.Led.LoadPos(r, self.tem[r]) # 亮度为0 self.Led.Show() sleep_ms(delay) Display.lock.release() _thread.exit() def clear(self): self.stop() self.Led.fill((0, 0, 0)) self.Led.Show() def __show(self, it, color): it = iter(it) for r in range(25): col = next(it) self.Led.LoadPos(r, color if col else black) self.Led.Show() def show(self, images, wait=True, color=Red, *, loop=False, delay=500, clear=False): if isinstance(images, str): images = CharData[images] if isinstance(images, list) and (isinstance(images[0], Image) or isinstance(images[0], list)): for i in images: self.__show(i, color) sleep_ms(delay) try: while loop: for i in images: self.__show(i, color) sleep_ms(delay) except Exception as e: self.Led.fill((0, 0, 0)) self.Led.Show() else: it = iter(images) self.__show(it, color) try: while loop: self.__show(it, color) except Exception as e: self.Led.fill((0, 0, 0)) self.Led.Show() def get_pixel(self, x=0, y=0): print("get_pixel will be supported in the future.") def set_pixel(self, x=0, y=0, value=9): print("set_pixel will be supported in the future.") def on(self): self.clear() def off(self): self.clear() def is_on(self): return self.Led != None
class Display: def __init__(self): self.Led = Pixel() self.tem = [[0, 0, 0]] * 25 # 显示缓存区m= def Disrupt_Col(color): a = color[-1] while True: if color_num != 1: import random random.shuffle(color) if a != color[0]: break def scroll(self, val, color=Red, delay=150): pixel_col = [[0, 0, 0]] * 25 # 显示缓存区m= val = str(val) + ' ' color_num = 1 if color != Red: if isinstance(color[0], list): color_num = len(color) # self.Disrupt_Col(color) #打乱颜色顺序 col_cnt = 0 it = iter(color) for val1 in val: val2 = CharData[val1] if color_num == 1: now_col = color else: if col_cnt < color_num: now_col = next(it) # 确定当前字符的颜色 else: col_cnt = 0 it = iter(color) now_col = next(it) col_cnt += 1 for i in range(25): # 为字符的像素点添加颜色 if val2[i] == 1: pixel_col[i] = now_col else: pixel_col[i] = [0, 0, 0] for i in range(6): # 开始滚动显示 for t in range(4): self.tem[20 - (t * 5):20 - (t * 5) + 5] = self.tem[20 - ((t + 1) * 5):20 - ((t + 1) * 5) + 5] # 数据向前移动5位 if i == 5: self.tem[0:5] = Zero[0:5] # 每个字符之间间隔一行 else: self.tem[0:5] = pixel_col[20 - (i * 5):20 - (i * 5) + 5] for r in range(25): self.Led.LoadPos(r, self.tem[r]) # 亮度为0 self.Led.Show() sleep_ms(delay) def clear(self): self.Led.fill((0, 0, 0)) self.Led.Show() def __show(self, it, color): it = iter(it) for r in range(25): col = next(it) self.Led.LoadPos(r, color if col else black) self.Led.Show() def show(self, images, color=Red, *, loop=False, delay=500): if isinstance(images, str): images = CharData[images] if isinstance(images, list) and (isinstance(images[0], Image) or isinstance(images[0], list)): for i in images: self.__show(i, color) sleep_ms(delay) try: while loop: for i in images: self.__show(i, color) sleep_ms(delay) except Exception as e: self.Led.fill((0, 0, 0)) self.Led.Show() else: it = iter(images) self.__show(it, color) try: while loop: self.__show(it, color) except Exception as e: self.Led.fill((0, 0, 0)) self.Led.Show()