import machine
import time
import board
import busio
import adafruit_ssd1306
from PIL import Image, ImageDraw, ImageFont
# Constants
SCREEN_WIDTH = 128
SCREEN_HEIGHT = 64
# Initialize I2C bus
i2c = busio.I2C(board.SCL, board.SDA)
# Initialize the SSD1306 OLED display
oled = adafruit_ssd1306.SSD1306_I2C(SCREEN_WIDTH, SCREEN_HEIGHT, i2c)
# Clear the display
oled.fill(0)
oled.show()
# Create a blank image with a white background
image = Image.new("1", (oled.width, oled.height))
draw = ImageDraw.Draw(image)
# Load a font
font = ImageFont.load_default()
# Display text
text = "Robotronix"
text_x = 0
text_y = 2
draw.text((text_x, text_y), text, font=font, fill=1)
# Show the image on the OLED display
oled.image(image)
oled.show()
# Define the analog pin where the potentiometer is connected (e.g., GPIO 34)
potentiometer_pin = machine.ADC(machine.Pin(34))
lednum = [
18,2, 4, 16, 17, 5
]
while True:
# Read the analog value (0-4095)
pot_value = potentiometer_pin.read()
mapped_value = int((pot_value / 4095) * 5)
# Turn on LEDs below mapped_value, and turn off LEDs above it
for i in range(len(lednum)):
if i <= mapped_value:
machine.Pin(lednum[i], machine.Pin.OUT).on()
else:
machine.Pin(lednum[i], machine.Pin.OUT).off()