An analog joystick test

Hereā€™s a little test program for the analog joystick. What it shows in my case is that the joystick does not (electrically) return to center when pressed to the right and then released slowly (in the other 3 directions it does return to center). It always mechanically returns to center. YMMV.

#include <MAKERphone.h>

MAKERphone mp;

void setup() {
  mp.begin(0);
}

void loop() {
  mp.update();
  mp.display.setTextColor(TFT_YELLOW);
  mp.display.setTextFont(2);
  int x = mp.buttons.getJoystickX();
  int y = mp.buttons.getJoystickY();
  mp.display.fillScreen(TFT_BLACK);
  mp.display.setCursor(45,50);
  mp.display.print(x);
  mp.display.setCursor(85,50);
  mp.display.print(y);

  CRGB ledvalue[4];
  ledvalue[0].red = y*255/1100;
  ledvalue[0].green = (x+y)*255/2200;
  ledvalue[0].blue = abs(x-y)*255/1100;
  ledvalue[1].red = ledvalue[0].blue;
  ledvalue[1].green = ledvalue[0].red;
  ledvalue[1].blue = ledvalue[0].green;
  ledvalue[2].red = ledvalue[0].green;
  ledvalue[2].green = ledvalue[0].blue;
  ledvalue[2].blue = ledvalue[0].red;
  ledvalue[3].red = ledvalue[0].blue;
  ledvalue[3].green = ledvalue[0].green;
  ledvalue[3].blue = ledvalue[0].red;
  for(int i=0; i<8; i++) mp.leds[i] = ledvalue[i%4];
}

The rainbow LEDs effect is just for fun.

Wow, thatā€™s really cool Frank!

I just tried it and got everything as itā€™s supposed to be. Could you try checking some joints on your Joystick?

The program is really simple and really cool, weā€™ll post it online if itā€™s cool with you so everyone can try it. :slight_smile:

Robert

2 Likes

Thereā€™s another mainboard on a slowboat from Croatia heading my way with a different joystick on it. I suspect the one Iā€™m using for testing has some sort of mechanical play/hysteresis inside that prevents the resistive contact from sliding all the way back to center from the right. Weā€™ll see what the other joystick does. For right now itā€™s fine as I donā€™t have a real analog joystick application in mind.

Itā€™s already posted online if itā€™s here under the C++ apps topic, isnā€™t it; so anyone can try it right now (except for those poor souls that are having USB connectivity problems).

2 Likes

Okay, tell us if that one works.

Yes, itā€™s here now, but since weā€™ve now created some more programs and the users like you have done so too, weā€™re planning to put it on our website, just like we did with apps and games for MAKERbuino.

Of course, the creator of the app gets credited for it!

1 Like