mechatronics/src/ESP32/6_motor.py

107 lines
2.7 KiB
Python

from machine import Pin
import utime
class taller3:
pin_board = Pin(2, Pin.OUT, value = 0)
pin_yellow = Pin(25, Pin.OUT, value = 0)
pin_white = Pin(26, Pin.OUT, value = 0)
pin_green = Pin(27, Pin.OUT, value = 0)
# Pin input
# 34
button_1 = Pin(32, Pin.IN, Pin.PULL_UP)
button_2 = Pin(35, Pin.IN, Pin.PULL_UP)
button_3 = Pin(34, Pin.IN, Pin.PULL_UP)
In1 = Pin(5, Pin.OUT, value = 0)
In2 = Pin(18, Pin.OUT, value = 0)
In3 = Pin(19, Pin.OUT, value = 0)
In4 = Pin(21, Pin.OUT, value = 0)
motor_pin = {In1, In2, In3, In4}
s1 = Stepper.create(In1, In2, In3, In4)
s1.step(1018, -1)
paso_1 = (
int('1000', 2),
int('0100', 2),
int('0010', 2),
int('0001', 2)
)
paso_2 = (
int('1100', 2),
int('0110', 2),
int('0011', 2),
int('1001', 2)
)
medio_paso = {
int('1000', 2),
int('1100', 2),
int('0100', 2),
int('0110', 2),
int('0011', 2),
int('0001', 2),
int('1001', 2),
}
SLEEP_MS = 500
DELAY_MS = 120
sentido = True
config - 1
bobinas = list()
def __init__(self):
for i in motor_pin:
bobinas.append(i)
while True:
if not button_1.value():
utime.sleep_ms(self.DEBOUNCE_MS)
print("btn1")
pin_green.value(not pin_green.value())
motor_int_1.value(not motor_int_1.value())
continue
if not button_2.value():
utime.sleep_ms(self.DEBOUNCE_MS)
print("btn2")
pin_white.value(not pin_white.value())
motor_int_2.value(not motor_int_2.value())
continue
if not button_3.value():
utime.sleep_ms(self.DEBOUNCE_MS)
print("btn3")
pin_yellow.value(not pin_yellow.value())
motor_int_3.value(not motor_int_3.value())
continue
def main():
program = taller3()
if __name__ == '__main__':
main()
if not self.button_2.value():
utime.sleep_ms(self.DEBOUNCE_MS)
print("btn2")
self.pin_white.value(not self.pin_white.value())
continue
if not self.button_3.value():
utime.sleep_ms(self.DEBOUNCE_MS)
print("btn3")
self.pin_yellow.value(not self.pin_yellow.value())
continue