wrightmac
Published

ItsyBitsy JoyDraw

An ItsyBitsy, a joystick, 128x64 OLED, CircuitPython and its time to draw.

BeginnerShowcase (no instructions)30 minutes613
ItsyBitsy JoyDraw

Things used in this project

Hardware components

Adafruit ItsyBitsy M4 Express
×1
128x64 OLED
×1
Generic 2-axis joystick with button
×1

Story

Read more

Schematics

Joydraw Schematic

Code

IB Joydraw

Python
CircuitPython for the ItsyBitsy M4 express.
# ItsyBitsy stickDraw

import board
import time
import busio
import digitalio
import analogio
import adafruit_ssd1306
from simpleio import map_range
from adafruit_hid.mouse import Mouse

# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)

mouse = Mouse()

# Create the display
display = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c)
display.fill(0)
display.show()

# Setting up the Joystick (mouse)
x_axis = analogio.AnalogIn(board.A0)
y_axis = analogio.AnalogIn(board.A1)

# Setup the Clear Screen button
select = digitalio.DigitalInOut(board.A2)
select.direction = digitalio.Direction.INPUT
select.pull = digitalio.Pull.UP

pot_min = 0.00
pot_max = 3.29
step = (pot_max - pot_min) / 20.0

def get_voltage(pin):
    return (pin.value * 3.3) / 65536

def steps(axis):
    # creating steps from 0-20
    return round((axis - pot_min) / step)

# Time to go to work
while True:

    x = map_range(x_axis.value, 0, 65535, 128 - 1, 0)
    y = map_range(y_axis.value, 0, 65535, 0, 64 - 1)

    # Check for Clear Screen button
    if select.value is False:
        mouse.click(Mouse.LEFT_BUTTON)
        # Debounce delay
        time.sleep(0.2)
        # Clear the screen
        display.fill(0)
        display.show()

    # Drawing path on the screen
    display.pixel(int(x), int(y), 1)
    display.show()

Credits

wrightmac

wrightmac

16 projects • 22 followers
Network geek by day, apprentice hardware hacker by night, curious-tinkerer always, and Apple Fanboy since 1984!

Comments