Changes between Version 1 and Version 2 of ControlSystems/SoftwareTeam/Training/GettingStarted/Debouncing


Ignore:
Timestamp:
Feb 14, 2020, 1:15:14 AM (5 years ago)
Author:
David Albert
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/Training/GettingStarted/Debouncing

    v1 v2  
    22
    33{{{
     4package frc.robot;
     5
     6import edu.wpi.first.wpilibj.TimedRobot;
    47import edu.wpi.first.wpilibj.XboxController;
    58import edu.wpi.first.wpilibj.Timer;
    69
    7 ...
    8 public void robotInit() {
    9    xbox = new XboxController(0);
    10    debounce = new Timer();
    11    debounce.start();
     10public 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  }
    1233}
    1334
    14 public void robot.periodic() {
    15    if (xbox.getAButton()) {
    16        // A button pressed
    17        if (debounce.hasPeriodPassed(0.5)) {
    18            // more than half-second since last press
    19            System.out.println("A button pressed!");
    20            // restart debounce timer so we ignore presses in next half second
    21            debounce.reset();
    22        }
    23    }
    24 }
    2535}}}
     36
     37Try commenting out the if statement (and its closing brace) and see what happens when you press the A button.