Adafruit_Learning_System_Gu.../CircuitPython_Knob_Sketcher/pixel_play/code.py
2022-02-23 13:04:53 -05:00

37 lines
831 B
Python
Executable file

# SPDX-FileCopyrightText: 2018 Carter Nelson for Adafruit Industries
#
# SPDX-License-Identifier: MIT
# Import the needed libraries
import time
import random
import board
import busio
from digitalio import DigitalInOut
import adafruit_ssd1306
# Create I2c bus
i2c = busio.I2C(board.SCL, board.SDA)
# Define display dimensions and I2C address
WIDTH = 128
HEIGHT = 64
ADDR = 0x3d
# Create the digital out used for display reset
rst = DigitalInOut(board.D7)
# Create the display
display = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=ADDR, reset=rst)
display.fill(0)
display.show()
# Loop forever drawing random pixels
while True:
for _ in range(500):
x = random.randrange(WIDTH)
y = random.randrange(HEIGHT)
display.pixel(x, y, 1)
display.show()
time.sleep(0.5)
display.fill(0)