def main(): device = get_device() print("Testing basic canvas graphics...") for _ in range(2): with canvas(device) as draw: primitives(device, draw) time.sleep(5) print("Testing contrast (dim/bright cycles)...") for _ in range(5): for level in range(255, -1, -10): device.contrast(level) time.sleep(0.1) time.sleep(0.5) for level in range(0, 255, 10): device.contrast(level) time.sleep(0.1) time.sleep(1) print("Testing display ON/OFF...") for _ in range(5): time.sleep(0.5) device.hide() time.sleep(0.5) device.show() print("Testing clear display...") time.sleep(2) device.clear() print("Testing screen updates...") time.sleep(2) for x in range(40): with canvas(device) as draw: now = datetime.datetime.now() draw.text((x, 4), str(now.date()), fill="white") draw.text((10, 16), str(now.time()), fill="white") time.sleep(0.1)
def main(): img_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'images', 'S.png')) logo = Image.open(img_path).convert("RGBA") fff = Image.new(logo.mode, logo.size, (255,) * 4) background = Image.new("RGBA", device.size, "white") posn = ((device.width - logo.width) // 2, 0) while True: for angle in range(0, 360, 1000): rot = logo.rotate(0, resample=Image.BILINEAR) img = Image.composite(rot, fff, rot) background.paste(img, posn) device.display(background.convert(device.mode)) if __name__ == "__main__": try: device = get_device() main() except KeyboardInterrupt: pass
def show(device): # use custom font font_path = os.path.abspath( os.path.join(os.path.dirname(__file__), 'fonts', 'code2000.ttf')) # 导入字体文件 font2 = ImageFont.truetype(font_path, 20) #设置字体类型和字体大小 # 开始输出 with canvas(device) as draw: # draw.text((x,y),"输出内容",font=字体,fill=颜色) # 这3行基本占满了128*64的oled屏幕 draw.text((0, 0), "一二三四五", font=font2, fill="white") draw.text((0, 22), "六七八九十", font=font2, fill="white") draw.text((0, 44), "Hello World", font=font2, fill="white") def main(): # 如果不写在循环里,执行完程序就退出了,就看不到内容 while True: show(device) time.sleep(5) if __name__ == "__main__": try: device = get_device() # 获取并输出设备信息 demo_opts.get_device() main() except KeyboardInterrupt: # ctrl+c退出 pass
(histogramTime[timePlusOne], histogramData[timePlusOne], histogramTime[htime], histogramData[htime]), fill="orange") histogramData.pop(len(histogramTime) - 1) draw.rectangle((minHistLenght, maxHistHeight, minHistLenght + 27, maxHistHeight + 13), fill="black", outline="white") draw.text((minHistLenght + 2, maxHistHeight + 2), "{0:.2f}".format(READ_ADC[0]), fill="white") if READ_ADC[0] > peak[0]: peak.insert(0, READ_ADC[0]) if __name__ == "__main__": device = get_device(actual_args=["--i2c-address", "0x3D"]) device2 = get_device(actual_args=["--i2c-address", "0x3C"]) histogramData, histogramTime = init_histogram() liste = [0, 0] global HIST_VALUES HIST_VALUES = zeros(128) while True: main(device, histogramData, histogramTime, liste) mainhist(device2) time.sleep(REFRESH_INTERVAL)
def test_get_device_config_file_missing(): """ Loading a missing config file throws an error. """ with pytest.raises(IOError): get_device(['-f', 'foo'])
def increase_population(): blue_pilled_population.append( [randint(0, device.width), 0, gauss(1.2, 0.6)]) while True: clock += 1 with regulator: with canvas(device, dither=True) as draw: for person in blue_pilled_population: x, y, speed = person for rgb in wrd_rgb: if 0 <= y < device.height: draw.point((x, y), fill=rgb) y -= 1 person[1] += speed if clock % 5 == 0 or clock % 3 == 0: increase_population() while len(blue_pilled_population) > max_population: blue_pilled_population.pop(0) if __name__ == "__main__": try: matrix(get_device()) except KeyboardInterrupt: pass
def __init__(self): self.font = make_font("miscfs_.ttf", 12) self.device = get_device() self.term = terminal(self.device, self.font)
def __init__(self): self.device = get_device()
def kill(): device = get_device() show(device)