from machine import Pin, I2C,ADC
import ssd1306
import time
# 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)
oled.pixel(5, 5,5)
oled.show()
oled.fill(0)
time.sleep_ms(1000)
oled.pixel(15, 5,5)
led=Pin(12, Pin.OUT)
led.value(1)
photon=ADC(Pin(27))
photon.atten(ADC.ATTN_11DB) #Full range: 3.3v
oled.show()
# Define grid size
grid_size = 30
while True:
oled.fill(0)
# Map the voltage value to a pixel intensity (0 to grid_size)
# Draw the grid
voltage = (photon.read() / 4095) * 3.3 # Calculate voltage
pixel_intensity = int((voltage / 3.3) * grid_size)
for x in range(grid_size):
for y in range(grid_size):
if x + y < pixel_intensity:
oled.pixel(x * (oled_width // grid_size), y * (oled_height // grid_size), 1)
oled.text('Voltage: {:.2f}V'.format(voltage), 40, 10)
oled.show()
time.sleep_ms(500)