#import ssd1306
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import time
button = Pin(15, Pin.IN, Pin.PULL_UP)
count=1
WIDTH =128
HEIGHT= 64
#Create the I2C connection
i2c=I2C(0,scl=Pin(17),sda=Pin(16),freq=200000)
#Initialize the OLED display
oled = SSD1306_I2C(WIDTH,HEIGHT,i2c)
button_status = True
while True:
if button.value() == 0:
if button_status:
button_status = False
print("Button Display Count is",count)
count+=1
name="THARANGA"
x= (WIDTH-(len(name)*8))//2
y= (HEIGHT-8)//2
oled.fill(0)
oled.text(name,x,y)
oled.show()
else:
button_status = True
print("Button Clear Count is",count)
count+=1
oled.fill(0)
oled.show()
while button.value() == 0:
time.sleep(0.1)
Loading
pi-pico-w
pi-pico-w