Skip to content

Instantly share code, notes, and snippets.

@benalb
Created April 10, 2021 06:34
Show Gist options
  • Save benalb/f4e800c4afcc6866ff4b0777625e2052 to your computer and use it in GitHub Desktop.
Save benalb/f4e800c4afcc6866ff4b0777625e2052 to your computer and use it in GitHub Desktop.
Use the Scroll Phat from pimoroni with esp32
""" Orginal code for microbit http://multiwingspan.co.uk/micro.php?page=phatscroll
this works with m5stickC (esp32 Pico)
from machine import I2C, Pin
from ScrollP import *
i2c = I2C(scl=Pin(32), sda=Pin(33))
sp = ScrollP(i2c)
sp.set_pixel(0,0,1)
sp.show()
"""
class ScrollP:
def __init__(self, i2c):
self.ADDRESS = 0x60
self.i2c = i2c
self.buffer = bytearray([0] * 11)
self.offset = 0
# set 5x11 mode
self.write_reg(0,0x03)
self.set_brightness(10)
self.show()
def write_reg(self,reg,value):
self.i2c.writeto(self.ADDRESS, bytes([reg,value]))
def set_pixel(self, x,y,value):
if value==1:
self.buffer[x] |= (1 << y)
else:
self.buffer[x] &= ~(1 << y)
def set_brightness(self,b):
self.write_reg(0x19,b)
def show(self):
data = bytearray([0x01]) + self.buffer + bytearray([0xff])
self.i2c.writeto(self.ADDRESS,data)
def clear(self):
self.buffer = bytearray([0] * 11)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment