You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Looks to me like that's an analog joystick, so you need to read analog values. You also don't need the pin modes that you had:

    var BTN = {Y: A0, X: A1, SELECT: B10};
    pinMode(BTN.SELECT, "input_pullup");
    
    setInterval(function() {
      yValue = analogRead(BTN.Y);
      xValue = analogRead(BTN.X);
      selectValue = !digitalRead(BTN.SELECT);
      console.log(xValue, yValue, selectValue);
    }, 500);
    

    Something like the above should print some values between 0 and 1, and you should be able to figure out when the joystick is over one side by looking at those values (eg less than 0.2 or greater than 0.8 maybe).

    Also one thing to watch out for is I'd really avoid while(true) in JavaScript because JS likes to execute small functions that execute quickly in order to be able to multi-task. I changed it for some code that checks every 500ms (twice a second)

About

Avatar for Gordon @Gordon started