from machine import Pin,I2C
import ssd1306
i2c = I2C(scl=Pin(15), sda=Pin(14), freq=100000)
lcd=ssd1306.SSD1306_I2C(128,64,i2c)
iconwineglass = [
0x00, 0x20, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
0x00, 0x18, 0x00, 0x00, 0x80, 0x20, 0x00, 0x00, 0xc0, 0x60, 0x18, 0x00,
0x40, 0x00, 0x08, 0x00, 0x30, 0x18, 0x06, 0x00, 0x20, 0x18, 0x06, 0x00,
0xc0, 0x60, 0x18, 0x00, 0x80, 0x20, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xff, 0x03,
0x03, 0x00, 0x00, 0x3f, 0x03, 0x00, 0x00, 0x3f, 0x03, 0x00, 0x00, 0xc3,
0x03, 0x00, 0x00, 0xc3, 0x03, 0x00, 0x00, 0xc3, 0x03, 0x00, 0x00, 0xc3,
0x03, 0x00, 0x00, 0xc3, 0x03, 0x00, 0x00, 0xc3, 0x03, 0x00, 0x00, 0x3f,
0x03, 0x00, 0x00, 0x3f, 0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0xe0, 0x00,
0x08, 0x00, 0x40, 0x00, 0x30, 0x00, 0x18, 0x00, 0x20, 0x00, 0x10, 0x00,
0xc0, 0xff, 0x07, 0x00, 0x80, 0xff, 0x07, 0x00
]
testgamp = [
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0xe0,
0x07, 0x00, 0x00, 0xe0, 0x06, 0x00, 0x00, 0x60, 0xf8, 0xff, 0xff, 0x1f,
0xf8, 0xff, 0xff, 0x1f, 0xe0, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x07,
0x40, 0x00, 0x00, 0x02, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x03, 0xc0, 0x00,
0x00, 0x0c, 0x30, 0x00, 0x00, 0x0c, 0x30, 0x00, 0x00, 0xe0, 0x07, 0x00,
0x00, 0xf0, 0x0f, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x80, 0x01, 0x00,
0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00,
0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00,
0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00,
0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0xc0, 0x03, 0x00,
0x00, 0xfc, 0x3f, 0x00, 0x00, 0xfc, 0x3f, 0x00
]
testicon = [
0xc0, 0x03, 0x20, 0x04, 0x10, 0x08, 0x10, 0x08, 0x1c, 0x38, 0x22, 0x44,
0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x02, 0x40, 0xfc, 0x3f, 0x00, 0x00,
0x12, 0x81, 0x89, 0x44, 0x44, 0x22, 0x22, 0x11
]
testicon2 = [
0x80, 0x0f, 0x40, 0x10, 0x60, 0x30, 0x90, 0x48, 0x08, 0x80, 0xc8, 0x83,
0x20, 0x84, 0x10, 0x48, 0x10, 0x08, 0x1c, 0x38, 0x22, 0x44, 0x01, 0x80,
0x01, 0x80, 0x01, 0x80, 0x02, 0x40, 0xfc, 0x3f
]
def printBits(value):
ret = [9,9,9,9, 9,9,9,9]
for x in range(0,8):
temp = value & 0x0001 # mask all but bit 0
if temp == 0x0001:
#print("Bit ", x, " = 1")
ret[x] = 1
else:
#print("Bit ", x, " = 0")
ret[x] = 0
value = value >> 1 # shift right repeat test
return ret
def showIcon(iconShow, xgap=0, ygap=0):
for y, row in enumerate(iconShow):
#for y, row in enumerate(icontest):
for x, c in enumerate(row):
retbin = printBits(c)
#print("Y / X :", y,"/",x," -- retbin ", retbin, "=", c)
for o in range(8):
if retbin[o] == 0:
#lcd.pixel((x * 8) + (7-o) + xgap , y + ygap, 0)
lcd.pixel((x * 8) + (7-o) + xgap , y + ygap, 0)
#pass
else:
#pass
#lcd.pixel((x * 8) + (7-o) + xgap, y + ygap, 1)
lcd.pixel((x * 8) + (7-o) + xgap, y + ygap, 1)
#
def showIcon2(iconShow, imagewidth, xgap=0, ygap=0):
posx = 0
posy = 0
for x, c in enumerate(iconShow):
retbin = printBits(c)
#print(x, "Y / X :", posy,"/",posx," -- retbin ", retbin, "=", c)
for o in range(8):
lcd.pixel((posx) + xgap , posy + ygap, retbin[o])
posx = posx + 1
if (posx > (imagewidth-1)):
posx = 0
posy = posy + 1
charStr = "Tell me WINE"
lcd.text(charStr, int((128-(len(charStr)*8))/2), 4)
lcd.rect(0, 0, 127, 15, 1)
lcd.rect(0, 16, 127, 48, 1)
showIcon2( iconwineglass, 32, 4, 20)
showIcon2( testicon2, 16, 50, 24)
showIcon2( testicon, 16, 55, 44)
showIcon2( testgamp, 32, 90, 20)
lcd.show() #display pix