import machine
import utime
from ssd1306 import SSD1306_I2C

sda=machine.Pin(20)
scl=machine.Pin(21)
i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)

oled = SSD1306_I2C(128, 32, i2c)



potentiometer = machine.ADC(26)
 
mtr_AI1 = machine.Pin(8, machine.Pin.OUT)
mtr_AI2 = machine.Pin(7, machine.Pin.OUT)
mtr_PWMa = machine.PWM(machine.Pin(6))
 
button_red = machine.Pin(15, machine.Pin.IN, machine.Pin.PULL_DOWN)
button_black = machine.Pin(2, machine.Pin.IN, machine.Pin.PULL_UP)
 
led_red = machine.Pin(10, machine.Pin.OUT)
led_green = machine.Pin(11, machine.Pin.OUT)
led_blue = machine.Pin(14, machine.Pin.OUT)
 

 


 
oled.text('Pico Motor Test', 0, 0)
oled.show()
utime.sleep(2)
 
led_red.value(1)
led_green.value(0)
led_blue.value(0)
utime.sleep(2)
 
led_red.value(0)
led_green.value(1)
led_blue.value(0)
utime.sleep(2)
 
led_red.value(0)
led_green.value(0)
led_blue.value(1)
 
mtr_PWMa.freq(50)
mtr_AI1.value(1)
mtr_AI2.value(0)
 
while True:
    
    speedvalue = int((potentiometer.read_u16())/500)
    
    mtr_PWMa.duty_u16(potentiometer.read_u16())
    
    if button_red.value() == 1:
        mtr_AI1.value(0)
        mtr_AI2.value(1)
        led_red.value(1)
        led_green.value(0)
        led_blue.value(0)
    
    if button_black.value() == 0:
        mtr_AI1.value(1)
        mtr_AI2.value(0)
        led_red.value(0)
        led_green.value(1)
        led_blue.value(0)
        
    oled.fill_rect(1,15,speedvalue,25,1)
    oled.show()
    oled.fill_rect(1,15,speedvalue,25,0)
    utime.sleep(0.25)
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
led1:A
led1:C
led2:A
led2:C
oled1:GND
oled1:VCC
oled1:SCL
oled1:SDA
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
btn2:1.l
btn2:2.l
btn2:1.r
btn2:2.r
pot1:GND
pot1:SIG
pot1:VCC