Skip to content

Commit 98cec09

Browse files
committed
Add power board example program
1 parent 3e06bdd commit 98cec09

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

docs/source/api/power-board.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,40 @@ the start.
102102
103103
This may be useful for debugging, but be sure to remove it in the
104104
competition, as you won't be allowed to touch the start button after a match has begun!
105+
106+
Example
107+
-------
108+
109+
.. code:: python
110+
111+
from sbot import *
112+
import time
113+
114+
r = Robot()
115+
116+
# Turn off output H0
117+
r.power_board.outputs[PowerOutputPosition.H0].is_enabled = False
118+
119+
120+
# Measure the current drawn by output H1
121+
amps = r.power_board.outputs[PowerOutputPosition.H1].current
122+
print(f"Current drawn by H1: {amps}")
123+
124+
125+
# Check the battery voltage
126+
volts = r.power_board.battery_sensor.voltage
127+
print(f"Battery voltage: {volts}")
128+
129+
130+
# Play a chord for 2 seconds
131+
chord_notes = [Note.D6, Note.A6, Note.C7, Note.D7, Note.F7]
132+
for note in chord_notes:
133+
r.power_board.piezo.buzz(2, note)
134+
135+
136+
# Play a tune
137+
tune_notes = [Note.D6, Note.G6, Note.A6, Note.D7, Note.F7, Note.A7, Note.C8]
138+
note_length = 0.25 # 4 notes per second
139+
for note in tune_notes:
140+
r.power_board.piezo.buzz(note_length, note)
141+
time.sleep(note_length)

0 commit comments

Comments
 (0)