from pushbutton import PushButton
import machine
from machine import Pin, ADC, I2C
import ssd1306
from time import sleep
# ESP32 Pin assignment
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
moteur = machine.Pin(26)
servo = machine.PWM(moteur,freq=50)
moteur2 = machine.Pin(0)
servo2 = machine.PWM(moteur2,freq=50)
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
vert = PushButton(18)
rouge = PushButton(4)
led_rouge = Pin(2, Pin.OUT)
led_verte = Pin(15, Pin.OUT)
axe = ADC(Pin(35))
axe.atten(ADC.ATTN_11DB)
code = 0
restart_devcode = 0
while True:
pot = axe.read() #definition of "pot" as the value of the potentiometer
if int(pot)<=511:
oled.fill(0)
if vert.was_pressed():
print("Axe_value = 0")
oled.text('Input = 0',10,25) #enrty of the input in the show list of the oled screen
code = 0
elif rouge.was_pressed():
print("Axe_value = 8")
oled.text('Input = 8',10,25)
code = 0
oled.text('Green:0 |Red:8',10,10) #Pre-view of the inputs before validation
if 511 < int(pot) <= 1022:
oled.fill(0)
if vert.was_pressed():
print("Axe_value = 1")
oled.text('Input = 1',10,25)
code = 0
elif rouge.was_pressed():
print("Axe_value = 9")
oled.text('Input = 9',10,25)
if code == 3:
code += 1
else:
code = 0
oled.text('Green:1 |Red:9',10,10) #Pre-view of the inputs before validation
elif 1022 < int(pot) <= 1533:
oled.fill(0)
if vert.was_pressed():
print("Axe_value = 2")
oled.text('Input = 2',10,25)
if code == 1:
code += 1
else:
code = 0
elif rouge.was_pressed():
print("Axe_value = A")
oled.text('Input = A',10,25)
code = 0
oled.text('Green:2 |Red:A',10,10) #Pre-view of the inputs before validation
elif 1533 < int(pot) <= 2044:
oled.fill(0)
if vert.was_pressed():
print("Axe_value = 3")
oled.text('Input = 3',10,25)
code = 0
elif rouge.was_pressed():
print("Axe_value = B")
oled.text('Input = B',10,25)
code = 0
oled.text('Green:3 |Red:B',10,10) #Pre-view of the inputs before validation
elif 2044 < int(pot) <= 2555:
oled.fill(0)
if vert.was_pressed():
print("Axe_value = 4")
oled.text('Input = 4',10,25)
code = 0
elif rouge.was_pressed():
print("Axe_value = C")
oled.text('Input = C',10,25)
if code == 4:
code += 1
else:
code = 0
oled.text('Green:4 |Red:C',10,10) #Pre-view of the inputs before validation
elif 2555 < int(pot) <= 3066:
oled.fill(0)
if vert.was_pressed():
print("Axe_value = 5")
oled.text('Input = 5',10,25)
code = 0
elif rouge.was_pressed():
print("Axe_value = D")
oled.text('Input = D',10,25)
code = 0
oled.text('Green:5 |Red:D',10,10) #Pre-view of the inputs before validation
elif 3066 < int(pot) <= 3577:
oled.fill(0)
if vert.was_pressed():
print("Axe_value = 6")
oled.text('Input = 6',10,25)
if code == 0:
code += 1
else:
code = 0
elif rouge.was_pressed():
print("Axe_value = E")
oled.text('Input = E',10,25)
code = 0
oled.text('Green:6 |Red:E',10,10) #Pre-view of the inputs before validation
elif 3577 < int(pot) <= 4095:
oled.fill(0)
if vert.was_pressed():
print("Axe_value = 7")
oled.text('Input = 7',10,25)
code = 0
restart_devcode = 0
elif rouge.was_pressed():
print("Axe_value = F")
oled.text('Input = F',10,25)
if code == 2:
code += 1
else:
code = 0
restart_devcode = restart_devcode + 1
oled.text('Green:7 |Red:F',10,10) #Pre-view of the inputs before validation
print(code)
if code == int(5):
oled.fill(0)
oled.text('Safe opened',10,25)
led_verte.value(1)
led_rouge.value(0)
servo.duty(30)
sleep(1)
led_verte.value(0)
led_rouge.value(1)
sleep(0.5)
servo.duty(60)
oled.show()
if restart_devcode == 6:
servo2.duty(30)
sleep(1)
servo2.duty(75)
restart_devcode = 0
sleep(0.5)