forked from pimoroni/inventorhatmini-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_internals.py
More file actions
39 lines (28 loc) · 1005 Bytes
/
read_internals.py
File metadata and controls
39 lines (28 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import time
from inventorhatmini import InventorHATMini, NUM_MOTORS
"""
Shows how to read the internal sensors of Inventor HAT Mini.
Press "User" to exit the program.
"""
# Constants
MOTOR_NAMES = ["A", "B"] # Friendly names to give the encoders
# Create a new InventorHATMini
board = InventorHATMini(init_leds=False)
# Set the motors spinning so that a current can be measured
for motor in board.motors:
motor.duty(1.0)
# Read the internal sensors until the user button is pressed
while not board.switch_pressed():
# Read the voltage sense and print the value
voltage = board.read_voltage()
print("V =", round(voltage, 4), end=", ")
# Read the current sense of each motor and print the value
for i in range(NUM_MOTORS):
current = board.read_motor_current(i)
print(f"Current {MOTOR_NAMES[i]} = ", round(current, 4), end=", ")
# Print a new line
print()
time.sleep(0.5)
# Disable the motors
for motor in board.motors:
motor.disable()