Browse Source

Add main file with example to measure distance

master
Elis Axelsson 5 years ago
parent
commit
ad936a68c6
  1. 9
      README.org
  2. 20
      tablecode/main.py

9
README.org

@ -13,14 +13,9 @@ picocom /dev/ttyUSB0 -b115200
* Small card
** Set up distance measuring
#+begin_src python
from hcsr04 import HCSR04
import time
import tablecode.main
sensor = HCSR04(trigger_pin=16, echo_pin=0)
while True:
print(sensor.distance_cm())
time.sleep(1)
tablecode.main.distance(16, 0)
#+end_src
** HCSR04 Pins

20
tablecode/main.py

@ -0,0 +1,20 @@
def blink():
import machine, time
print("blink")
pin = machine.Pin(2, machine.Pin.OUT)
while True:
pin.value(not pin.value())
time.sleep_ms(500)
def distance(trigger, echo):
from hcsr04 import HCSR04
import time
sensor = HCSR04(trigger_pin=trigger, echo_pin=echo)
while True:
print(sensor.distance_cm())
time.sleep(1)
Loading…
Cancel
Save