Changes between Version 1 and Version 2 of ControlSystems/SoftwareTeam/Training/GettingStarted/Debouncing
- Timestamp:
- Feb 14, 2020, 1:15:14 AM (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/Debouncing
v1 v2 2 2 3 3 {{{ 4 package frc.robot; 5 6 import edu.wpi.first.wpilibj.TimedRobot; 4 7 import edu.wpi.first.wpilibj.XboxController; 5 8 import edu.wpi.first.wpilibj.Timer; 6 9 7 ... 8 public void robotInit() { 9 xbox = new XboxController(0); 10 debounce = new Timer(); 11 debounce.start(); 10 public class Robot extends TimedRobot { 11 XboxController xbox; 12 Timer debounce; 13 14 @Override 15 public void robotInit() { 16 xbox = new XboxController(0); 17 debounce = new Timer(); 18 debounce.start(); 19 } 20 21 @Override 22 public void robotPeriodic() { 23 if (xbox.getAButton()) { 24 // A button pressed 25 if (debounce.hasPeriodPassed(0.5)) { 26 // more than half-second since last press 27 System.out.println("A button pressed!"); 28 // restart debounce timer so we ignore presses in next half second 29 debounce.reset(); 30 } 31 } 32 } 12 33 } 13 34 14 public void robot.periodic() {15 if (xbox.getAButton()) {16 // A button pressed17 if (debounce.hasPeriodPassed(0.5)) {18 // more than half-second since last press19 System.out.println("A button pressed!");20 // restart debounce timer so we ignore presses in next half second21 debounce.reset();22 }23 }24 }25 35 }}} 36 37 Try commenting out the if statement (and its closing brace) and see what happens when you press the A button.