You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

58 lines
1.1 KiB

from pinouts import NodeMCU as pins
from hcsr04 import HCSR04
import time
import machine
def getDistance():
sensor = HCSR04(trigger_pin=pins.D2, echo_pin=pins.D3)
return sensor.distance_cm()
def getMovement():
sensor = machine.Pin(pins.D2, mode=machine.Pin.IN, pull=None)
return sensor.value()
def resetRelay():
relayUp = machine.Pin(pins.D5, mode=machine.Pin.OUT)
relayDown = machine.Pin(pins.D6, mode=machine.Pin.OUT)
relayUp.value(1)
relayDown.value(1)
def toggleRaiseUp():
relayUp = machine.Pin(pins.D5, mode=machine.Pin.OUT)
relayUp.value(not relayUp.value())
def toggleLowerDown():
relayDown = machine.Pin(pins.D6, mode=machine.Pin.OUT)
relayDown.value(not relayDown.value())
def goCrazy():
resetRelay()
while True:
print("Lowest Distance: " + str(getDistance()))
print("Movement: " + str(getMovement()))
toggleRaiseUp()
time.sleep(3)
print("Highest Distance: " + str(getDistance()))
print("Movement: " + str(getMovement()))
toggleRaiseUp()
toggleLowerDown()
time.sleep(3)
toggleLowerDown()