Browse Source

Cleanup and make functions to just read values instead of doing things

forever and ever
master
Elis Axelsson 5 years ago
parent
commit
b6de0dc4ef
  1. 12
      README.org
  2. 20
      code/main.py

12
README.org

@ -27,9 +27,11 @@ ampy --port /dev/ttyUSB0 put hcsr04.py
*** Set up distance measuring
#+begin_src python
import main
import main, time
main.distance()
while True:
print(main.getDistance())
time.sleep(1)
#+end_src
** Movement sensor
@ -42,9 +44,11 @@ main.distance()
*** Set up movement sensor
#+begin_src python
import main
import main, time
main.movement()
while True:
print(main.getMovement())
time.sleep(0.5)
#+end_src
** Relay

20
code/main.py

@ -4,28 +4,16 @@ import time
import machine
def blink():
pin = machine.Pin(2, machine.Pin.OUT)
while True:
pin.value(not pin.value())
time.sleep_ms(500)
def distance():
def getDistance():
sensor = HCSR04(trigger_pin=pins.D2, echo_pin=pins.D3)
while True:
print(sensor.distance_cm())
time.sleep(1)
return sensor.distance_cm()
def movement():
def getMovement():
sensor = machine.Pin(pins.D2, mode=machine.Pin.IN, pull=None)
while True:
print(sensor.value())
time.sleep(0.5)
return sensor.value()
def resetRelay():

Loading…
Cancel
Save