"""
Prénom : Maxime
Nom : Kapczuk
Classe : 5J
"""
from machine import Pin
from utime import sleep
from machine import PWM
from machine import I2C
from ssd1306 import SSD1306_I2C
i2c=I2C(0,sda=Pin(0), scl=Pin(1), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
button = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_UP)
led_rouge = Pin(2, Pin.OUT)
led_verte = Pin(3,Pin.OUT)
pwm = PWM(Pin(4))
pwm.freq(50)
def cycleservo(position):
pwm.duty_u16(position)
sleep(0.01)
x=0
y=0
while True:
if not button.value():
oled.fill(0)
oled.text("Le bouton est enfoncé", 0, 0)
oled.show()
led_verte.value(1)
led_rouge.value(0)
while x == 0:
for tour in range(1000,9000,50):
cycleservo(tour)
x=1
y=0
sleep(2)
else:
oled.fill(0)
oled.text("Pas d'action sur le bouton", 0, 0)
oled.show()
led_rouge.value(1)
led_verte.value(0)
while y == 0:
for tour in range(9000,1000,-50):
cycleservo(tour)
x=0
y=1
sleep(2)
sleep(0.1)