Browse Source

Put the distance measuring in the new class

master
Elis Axelsson 5 years ago
parent
commit
ad57b92bca
  1. 7
      code/main.py
  2. 13
      code/table.py

7
code/main.py

@ -1,15 +1,8 @@
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.D4, mode=machine.Pin.IN, pull=None)

13
code/table.py

@ -14,3 +14,16 @@ class Table:
# Relay to move up and down
self.relay_up = machine.Pin(pins.D5, mode=machine.Pin.OUT)
self.relay_down = machine.Pin(pins.D6, mode=machine.Pin.OUT)
def currentHeight(self):
"""
Get current height of the table in CM.
Might return False if measuring error.
"""
distance = self.hcsr04.distance_cm()
if distance > 0:
return distance
return False

Loading…
Cancel
Save