1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

problem with reading PS3 controller buttons

Discussion in 'Programming/Internet' started by AlfroJang80, Oct 8, 2018.

  1. AlfroJang80

    AlfroJang80 Guest

    I'm working on a camera slider mount with an X stepper (to move along slider), Y stepper (pan left right) and Z stepper (tilt up down). All of this is being controlled by a PS3 controller (PS3BT library).

    I've implemented a feature in which all three steppers move from one saved position to other and then back again.. this keeps repeating infinitely. It works fine - except I can't stop it - it's more of a programming issue I think. Here's the code in question

    // MultiStepper instance - at the top somewhere
    MultiStepper StepperControl;

    void loop(){
    if(PS3.getButtonClick(START)){ // START to start movement between two POS's.
    Serial.print("\n Starting Movement between POS1 and POS2");
    while(!PS3.getButtonClick(CROSS)){
    StepperControl.moveTo(POS1); // go to POS1
    StepperControl.runSpeedToPosition();
    delay(200);
    StepperControl.moveTo(POS2); // go to POS2
    StepperControl.runSpeedToPosition();
    delay(200);
    }
    }
    }


    My issue is that pressed X (cross) on the keypad, doesn't quit out of the loop. What I feel is happening is that the loop is running too fast and all the moveTo() commands are stacking on top of each other. And so, even if I do press X, too many moveTo() commands have already happened and it just keeps running those "queued" commands.

    I've also tried putting an if statement inside the while loop that breaks out of the loop when CROSS is pressed - no luck.

    // This isn't the entire code, just the parts I think are relevant.

    Login To add answer/comment
     

Share This Page