import machine
from machine import Pin, I2C
from utime import sleep
import time
import ssd1306 

# ESP32 Pin assignment 
i2c = I2C(0, scl=Pin(22), sda=Pin(21))

oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)

led = Pin(15, Pin.OUT)
ledInt = Pin(19, Pin.OUT)
 
timer = machine.Timer(0)  

def handleInterrupt(timer):
  ledInt.off()
  oled.fill(0)
  print("Interrupt Occured")
  oled.text('Interrupt', 5, 10)      
  oled.show()
  led.off()
  ledInt.on()
  sleep(1)
  ledInt.off()
  oled.fill(0)
  oled.show()
  

  
  

 
timer.init(period=2000, mode=machine.Timer.PERIODIC, callback=handleInterrupt)
 
while True:
  led.on()
  oled.text(str(time.ticks_ms()*0.001)+" s", 5, 10)      
  oled.show()
  sleep(0.5)
  led.off()
  sleep(0.5)
  oled.fill(0)
  oled.show()
  print(time.ticks_ms()*0.001)