garykac / amhs-robotics-4681

Repository for AMHS's FRC (FIRST Robotics Competition) team
3 stars 0 forks source link

Find a way so that when pressing a direction on the POV that it onlt triggers once #23

Closed RyanDecker123 closed 5 years ago

cmarley3-14 commented 5 years ago
boolean currentlyPressed = false;
int lifterLevel = 0; //Assuming we start at bottom
public void teleopPeriodic() {
    if (m_stick.getPOV() == 0) {
        if (lifterLevel < 7 && !currentlyPressed)
            lifterLevel++;
        currentlyPressed = true;
    } else if (m_stick.getPOV() == 0) {
        if (lifterLevel > 0 && !currentlyPressed)
            lifterLevel--;
        currentlyPressed = true;
    } else {
        currentlyPressed = false;
    }
    switch(lifterLevel) {
        case 0:
            m_lifter.GoToBottom();
            break;
        case 1:
            m_lifter.GoToFirstBallLevel();
            break;
        case 2:
            m_lifter.GoToFirstHatchLevel();
            break;
        case 3:
            m_lifter.GoToSecondBallLevel();
            break;
    //etc.
    }
}

A bit long and complicated, but this is my limited programming example. 🤞

amhsrobotics4681 commented 5 years ago
int intakeModeAdder= 1;
if (m_stick.getRawButtonPressed(6))
    intakeModeAdder = 0 - intakeModeAdder; //toggle between -1 and 1
    lifterLevel = lifterLevel + intakeModeAdder // Then this guy will be at either 0 or off by 1.
                                        //The we can maintain the levels and the switch statement.
if (m_stick.getPOV() == 0) {
    if (lifterLevel < 7 && !currentlyPressed)
        lifterLevel = lifterLevel + 2;
    currentlyPressed = true;
RyanDecker123 commented 5 years ago

i used this code and it works so problem solved