# ''' Imporft the ADC and time module '''
from machine import ADC, Pin, I2C
from ssd1306 import SSD1306_I2C
import time

# Potentiometers
POT1 = 0
POT2 = 1
POT3 = 2
POT4 = 3
#OLED intantiation
i2c=I2C(0,sda=Pin(21), scl=Pin(22), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
# Choose the ADC pin to read the ADC values
#Define the Pins to be used
adc_pins = [32, 33, 34, 35]  

# Setup pins for ADC
adcs = [ADC(Pin(adc_pins[POT1])),ADC(Pin(adc_pins[POT2])),
                ADC(Pin(adc_pins[POT3])), ADC(Pin(adc_pins[POT4]))]

#Set the ADC atenuation lel
[adc.atten(ADC.ATTN_11DB) for adc in adcs] 
[adc.width(ADC.WIDTH_12BIT) for adc in adcs] 




while True: 
# Let's read the adc values and print them to the OLED
    oled.fill(0)
    ADC1 = 3.3*adcs[POT1].read()/4095
    ADC2 = 3.3*adcs[POT2].read()/4095
    ADC3 = 3.3*adcs[POT3].read()/4095
    ADC4 = 3.3*adcs[POT4].read()/4095

    oled.text("ADC1 " + str(ADC1)+"V", 0, 0)
    oled.text("ADC2 " + str(ADC2)+"V", 0, 15)
    oled.text("ADC3 " + str(ADC3)+"V", 0, 35)
    oled.text("ADC4 " + str(ADC4)+"V", 0, 55)
    oled.show()
    time.sleep_ms(1)