from machine import Pin, I2C
from time import sleep_ms
from ssd1306 import SSD1306_I2C
WIDTH =128
HEIGHT= 64
i2c=I2C(0,scl=Pin(1),sda=Pin(0),freq=200000)
oled = SSD1306_I2C(WIDTH,HEIGHT,i2c)
count = 0
led_red = Pin(16,Pin.OUT)
btn_red = Pin(28,Pin.IN)
btn_green = Pin(27,Pin.IN)
Am = Pin(15,Pin.OUT)
Ap = Pin(14,Pin.OUT)
Bn = Pin(13,Pin.OUT)
Bp = Pin(12,Pin.OUT)
Am1 = Pin(5,Pin.OUT)
Ap1 = Pin(4,Pin.OUT)
Bn1 = Pin(3,Pin.OUT)
Bp1 = Pin(2,Pin.OUT)
def rew_motor1():
sleep_ms(1)
Bn.value(0)
Ap.value(1)
sleep_ms(1)
Ap.value(0)
Bp.value(1)
sleep_ms(1)
Bp.value(0)
Am.value(1)
sleep_ms(1)
Am.value(0)
Bn.value(1)
def rew_motor2():
sleep_ms(1)
Bn1.value(0)
Ap1.value(1)
sleep_ms(1)
Ap1.value(0)
Bp1.value(1)
sleep_ms(1)
Bp1.value(0)
Am1.value(1)
sleep_ms(1)
Am1.value(0)
Bn1.value(1)
while 1:
if btn_red.value():
led_red.toggle()
rew_motor1()
rew_motor2()
oled.text('led_red is on', 0, count)
oled.show()
count +=10
if btn_green.value():
led_red.toggle()
oled.text('led_red is off', 0, count)
oled.show()
count +=10
if count == 60:
oled.fill(0)
count = 0