Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from machine import Pin, PWM
- from ir_rx.nec import NEC_16
- import time
- pinIR = 17 # numero de PIN conectado al OUT del sensor IR
- pinLed = Pin(16, Pin.OUT)
- pinFoco1 = Pin(12, Pin.OUT)
- pinFoco2 = Pin(13, Pin.OUT)
- pinSonido = Pin(2, Pin.OUT)
- motorVelocidad_1 = PWM(10)
- motorVelocidad_2 = PWM(11)
- motorVelocidad_1.freq(500)
- motorVelocidad_2.freq(500)
- velocidad = 65000
- in1 = Pin(0, Pin.OUT)
- in2 = Pin(1, Pin.OUT)
- in3 = Pin(14, Pin.OUT)
- in4 = Pin(15, Pin.OUT)
- valueCode = -1
- moveMotor = False
- focoEncendidoApagado = True
- def callback(data):
- global valueCode
- global moveMotor
- global focoEncendidoApagado
- if(data != -1):
- valueCode = data
- if(data == 0 or data == 1 or data == 4 or data == 5): #Cambiar por el valor del control a usar
- moveMotor = True
- else:
- moveMotor = False
- if(data == 20): #Cambiar por el valor del control a usar
- if(focoEncendidoApagado == True):
- focoEncendidoApagado = False
- else:
- focoEncendidoApagado = True
- def encenderFocos():
- if(focoEncendidoApagado == False):
- pinFoco1.on()
- pinFoco2.on()
- else:
- pinFoco1.off()
- pinFoco2.off()
- def encenderLed():
- pinLed.on()
- time.sleep_ms(50)
- pinLed.off()
- time.sleep_ms(50)
- def MotorFrente(valorMotor):
- if(valorMotor):
- encenderLed()
- time.sleep_ms(100)
- in1.on()
- in2.off()
- in3.on()
- in4.off()
- def MotorAtras(valorMotor):
- if(valorMotor):
- encenderLed()
- time.sleep_ms(100)
- in1.off()
- in2.on()
- in3.off()
- in4.on()
- def MotorIz(valorMotor):
- if(valorMotor):
- in1.on()
- in2.off()
- in3.off()
- in4.on()
- def MotorDr(valorMotor):
- if(valorMotor):
- in1.off()
- in2.on()
- in3.on()
- in4.off()
- def MotorApagado(valor):
- if(valor == 2):
- in1.off()
- in2.off()
- in3.off()
- in4.off()
- pinIR = 17 # numero de PIN conectado al OUT del sensor IR
- pin_ir = Pin(pinIR, Pin.IN)
- # Cambia NEC_8 por la clase adecuada si es necesario
- ir_receiver = NEC_16(pin_ir, callback)
- pausaMotor = 800
- pausaMotorMove = 250
- while True:
- if(valueCode == 0): #Cambiar por el valor del control a usar
- encenderLed()
- MotorFrente(moveMotor)
- time.sleep_ms(pausaMotor)
- MotorApagado(2)
- valueCode = -1
- if(valueCode == 1): #Cambiar por el valor del control a usar
- encenderLed()
- MotorAtras(moveMotor)
- valueCode = -1
- time.sleep_ms(pausaMotor)
- MotorApagado(2)
- if(valueCode == 2): #Cambiar por el valor del control a usar
- encenderLed()
- MotorApagado(valueCode)
- valueCode = -1
- if(valueCode == 20): #Cambiar por el valor del control a usar
- encenderFocos()
- if(valueCode == 4): #Cambiar por el valor del control a usar
- MotorIz(moveMotor)
- time.sleep_ms(pausaMotorMove)
- MotorApagado(2)
- encenderLed()
- valueCode = -1
- if(valueCode == 5): #Cambiar por el valor del control a usar
- encenderLed()
- MotorDr(moveMotor)
- time.sleep_ms(pausaMotorMove)
- MotorApagado(2)
- encenderLed()
- valueCode = -1
- if(valueCode == 3): #Cambiar por el valor del control a usar
- encenderFocos()
- if(velocidad >= 65000):
- velocidad = 65000
- else:
- velocidad += 2000
- valueCode = -1
- if(valueCode == 7): #Cambiar por el valor del control a usar
- encenderFocos()
- if(velocidad <= 0):
- velocidad = 1000
- else:
- velocidad -= 2000
- valueCode = -1
- motorVelocidad_1.duty_u16(velocidad)
- motorVelocidad_2.duty_u16(velocidad)
Advertisement
Add Comment
Please, Sign In to add comment