Skip to content

Commit 77b2c6e

Browse files
committed
update readme
1 parent a0c01e3 commit 77b2c6e

File tree

1 file changed

+28
-35
lines changed

1 file changed

+28
-35
lines changed

README.md

+28-35
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ $ python3 -m venv hat_env
2525
$ source hat_env/bin/activate
2626
```
2727

28-
You may need to install the I2C development library:
29-
30-
```
31-
$ sudo apt install libi2c-dev
32-
```
33-
34-
and you will certainly need to turn I2C on in your boot configuration file.
35-
3628
Now use the setup.py script to build and install the module:
3729

3830
```
@@ -44,12 +36,8 @@ Now use the setup.py script to build and install the module:
4436
You should now be able to "import hub" in a Python3 script and have
4537
the module available to you.
4638

47-
Optionally the code may be compiled with "DEBUG\_I2C=1" to enable logging
48-
of the I2C traffic on the hub.
49-
50-
The code may be compiled with "USE\_DUMMY\_I2C=1" to use an ethernet local
51-
loopback as a fake I2C for test purposes.
52-
39+
Optionally the code may be compiled with "DEBUG\_UART=1" to enable logging
40+
of the UART traffic on the hub.
5341

5442
Documentation
5543
-------------
@@ -71,32 +59,37 @@ Usage
7159

7260
See the detailed documentation for the Python objects available.
7361

74-
To control a motor attached to port A:
75-
7662
```python
77-
from build_hat import BuildHAT
78-
79-
bh = BuildHAT()
80-
bh.port.A.motor.run_for_time(1000, 127) # run for 1000ms at maximum clockwise speed
81-
bh.port.A.motor.run_for_time(1000, -127) # run for 1000ms at maximum anticlockwise speed
82-
bh.port.A.motor.run_for_degrees(180, 127) # turn 180 degrees clockwise at maximum speed
83-
bh.port.A.motor.run_for_degrees(720, -127) # Make two rotations anticlockwise at maximum speed
84-
bh.port.A.motor.run_to_position(0, 127) # Move to top dead centre at maximum speed (positioning seems to be absolute)
85-
bh.port.A.motor.run_to_position(180, 127) # Move to 180 degrees forward of top dead centre at maximum speed
86-
```
63+
import time
64+
from signal import pause
65+
from buildhat import Motor
8766

88-
To rotate motor attached to port once clockwise when a button attached to port B is pressed:
67+
motor = Motor('A')
68+
motor.set_default_speed(30)
8969

90-
```python
91-
from build_hat import BuildHAT
92-
import time
70+
print("Position", motor.get_aposition())
71+
72+
def handle_motor(speed, pos, apos):
73+
print("Motor", speed, pos, apos)
74+
75+
motor.when_rotated = handle_motor
76+
77+
print("Run for degrees")
78+
motor.run_for_degrees(360)
79+
80+
print("Run for seconds")
81+
motor.run_for_seconds(5)
82+
83+
print("Run for rotations")
84+
motor.run_for_rotations(2)
9385

94-
bh = BuildHAT()
95-
while True:
96-
if bh.port.B.device.get() > 0: # test if button is pressed
97-
bh.port.A.motor.run_for_degrees(360, 127) # turn 360 degrees clockwise at maximum speed
98-
time.sleep(0.5) # Wait half a second for motor to finish turning
86+
print("Start motor")
87+
motor.start()
88+
time.sleep(3)
89+
print("Stop motor")
90+
motor.stop()
9991

92+
pause()
10093
```
10194

10295
Programming Bootloader

0 commit comments

Comments
 (0)