code.py
1 # SPDX-FileCopyrightText: 2018 Carter Nelson for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 import board 6 import busio 7 import adafruit_ssd1306 8 from simpleio import map_range 9 from analogio import AnalogIn 10 from digitalio import DigitalInOut 11 12 # Create the I2C bus 13 i2c = busio.I2C(board.SCL, board.SDA) 14 15 # Define display dimensions and I2C address 16 WIDTH = 128 17 HEIGHT = 64 18 ADDR = 0x3d 19 20 # Create the digital out used for display reset 21 rst = DigitalInOut(board.D7) 22 23 # Create the display 24 display = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=ADDR, reset=rst) 25 display.fill(0) 26 display.show() 27 28 # Create the knobs 29 x_knob = AnalogIn(board.A0) 30 y_knob = AnalogIn(board.A1) 31 32 while True: 33 x = map_range(x_knob.value, 0, 65535, WIDTH - 1, 0) 34 y = map_range(y_knob.value, 0, 65535, 0, HEIGHT - 1) 35 display.pixel(int(x), int(y), 1) 36 display.show()