Skip to content

Commit 1caed8a

Browse files
committed
put example into readme
1 parent dc6a1de commit 1caed8a

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

README.rst

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,32 @@ This is easily achieved by downloading
2828
Usage Example
2929
=============
3030

31-
.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
31+
.. code-block:: python
32+
33+
import time
34+
import board # comment this out if using pyserial
35+
import busio # comment this out if using pyserial
36+
import adafruit_tfmini
37+
38+
# Use hardware uart
39+
uart = busio.UART(board.TX, board.RX)
40+
41+
# Or, you can use pyserial on any computer
42+
#import serial
43+
#uart = serial.Serial("/dev/ttyS2", timeout=1)
44+
45+
# Simplest use, connect with the uart bus object
46+
tfmini = adafruit_tfmini.TFmini(uart)
47+
48+
# You can put in 'short' or 'long' distance mode
49+
tfmini.mode = adafruit_tfmini.MODE_SHORT
50+
print("Now in mode", tfmini.mode)
51+
52+
while True:
53+
print("Distance: %d cm (strength %d, mode %x)" %
54+
(tfmini.distance, tfmini.strength, tfmini.mode))
55+
time.sleep(0.1)
56+
3257
3358
Contributing
3459
============

0 commit comments

Comments
 (0)