Go Down

Topic: How to avoid the Thumb Joystick values from returning to original position (Read 27 times) previous topic - next topic



I´m new to programming in C, sorry for the bad and messy code.

I´m trying to move a square in a 32X16 LED matrix. The problem is that I can just move the square 1 pixel and then it will return to its original position.
What I want to achieve is moving the square in a direction "x" ,"y" and stay in that coordinate until I move again the thumbjoystick.

Here is the code:
Code: [Select]

#include <HT1632.h>
#include <images.h>

int mapY(int y);
int joystickY(int jy), joystickX(int jx);
int jx, mapeoX, x, jy, mapeoY, y;
int posY, posX;

void setup() {

void loop() {

    HT1632.drawImage(IMG_cuadro4X4, IMG_cuadro4X4_WIDTH,  IMG_cuadro4X4_HEIGHT, joystickX(jx), joystickY(jy));

int mapY(int y){
  return mapeoY;

int mapX(int x){
  return mapeoX;
int joystickY(int jy){
  int i;
  int posY=1;
  if(mapY(y)>=8 && mapY(y)<17){
      return posY;
        if (mapY(y)<=6 && mapY(y)>0){
          return posY;

int joystickX(int jx){
  int i;
  int posX=0;
  if(mapX(x)>=15 && mapX(x)<17){
      return posX;
        if (mapX(x)<=14 && mapX(x)>0){
          return posX;


Any ideas ?


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131