Skip to content

Commit eb1e32a

Browse files
committed
Add dutycycle-input example
1 parent 7c6ccea commit eb1e32a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

dutycycle-input/robot.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
3+
import wpilib
4+
5+
6+
class MyRobot(wpilib.TimedRobot):
7+
8+
def robotInit(self):
9+
"""Robot initialization function"""
10+
11+
self.dutyCycle = wpilib.DutyCycle(wpilib.DigitalInput(0))
12+
13+
def robotPeriodic(self):
14+
# Duty Cycle Frequency in Hz
15+
frequency = self.dutyCycle.getFrequency()
16+
17+
# Output of duty cycle, ranging from 0 to 1
18+
# 1 is fully on, 0 is fully off
19+
output = self.dutyCycle.getOutput()
20+
21+
wpilib.SmartDashboard.putNumber("Frequency", frequency)
22+
wpilib.SmartDashboard.putNumber("Duty Cycle", output)
23+
24+
25+
if __name__ == "__main__":
26+
wpilib.run(MyRobot)

run_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ BASE_TESTS="
1616
differential-drive-bot
1717
digital-communication
1818
dutycycle-encoder
19+
dutycycle-input
1920
elevator-profiled-pid
2021
elevator-simulation
2122
elevator-trapezoid-profile

0 commit comments

Comments
 (0)