i2c analog joy stick glitches

Duhjoker
Posts: 85
Joined: Mon Mar 20, 2017 8:09 am

i2c analog joy stick glitches

Postby Duhjoker » Mon Jan 15, 2018 1:09 am

hi guys

I'm having some problems with using a feather wing joys with my huzzah 32. I'm trying to implement a timer that repeats the analog movement so an object can be moved on screen constantly while the stick is being used. If I use the adafruit seesaw example bits as they stand into my game program every thing is fine. But I can only get the character to move one space at a time. When I try to implement the repeat action every thing goes haywire.

Up and right can be accessed at game start but I have to access my menu function before down can be used. Left cant be used at all. Ive retested the joy boards over and over and all works. I even rotated the screen so I could use the twin joy but it has the same glitch

Code: Select all

#include "Adafruit_seesaw.h"
#include <elapsedMillis.h>

Adafruit_seesaw ss1;
struct Player
{
  int player_x; 
  int player_y; 
  int room;
  int player_direction; 
  int player_directionRepeat;
};

Player player = { 160, 170, 3, 2, 0};

 #define IRQ_PIN1   13
 #define IRQ_PIN2   27
////////////////////////////////////////////////////////////////////////////
int last_x = 0, last_y = 0;

elapsedMillis MoveRepeat;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
  int y = ss1.analogRead(2);
   int x = ss1.analogRead(3);
   #define MoveRepeatRate 100 // set this for how long in milis to wait for auto repeat move
///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// 
void drawplayer(){

 if(x > 600 && last_x < 600 || ( 1 == player.player_directionRepeat && MoveRepeat >= MoveRepeatRate )){  ////if x is greater than 600 and last x was less than 600 do something
    Serial.println(F("UP")); ///LEFT  
      MoveRepeat = 0;
       player.player_directionRepeat = 1;
     tft.writeRectNBPP(player.player_x, player.player_y,  16, 16, 4, paulrearwa, palette); //// this mixed with the call below it calls bitmaps for walking 
    tft.writeRectNBPP(player.player_x, player.player_y, 16, 16, 4, paulrearwb, palette); ///// read above
      
     player.player_direction = 1; ////when movement ends player bitmap faces this direction paul rear
     player.player_y -= 4;    ///move player y - 4 pixels 
     if(checkcolision())     
    {
     player.player_y += 4;} ///causes player to stop when collision happens
     player.player_directionRepeat = 0;
    }
    if(player.player_y <= 16){    ////keeps player from walking off the screen. 
        player.player_y = 16;
    }
/////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////// 
 if(x < 400 && last_x > 400 || ( 1 == player.player_directionRepeat && MoveRepeat >= MoveRepeatRate )){
    Serial.println(F("DOWN")); ///RIGHT 
     MoveRepeat = 0;
      player.player_directionRepeat = 1;
     tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulfrontwa,palette);
    tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulfrontwb,palette);
    
    player.player_direction = 2; ////when movement ends player bitmap faces this direction paul rear
     player.player_y += 4;    ///move player y - 4 pixels 
     if(checkcolision())     
    {
     player.player_y -= 4;} ///causes player to stop when collision happens
     player.player_directionRepeat = 0;
    }
    if(player.player_y >= 224){
       player.player_y = 224;
  }
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
 if(y < 400 && last_y > 400 || ( 1 == player.player_directionRepeat && MoveRepeat >= MoveRepeatRate )){
    Serial.println(F("LEFT")); ///DOWN
     MoveRepeat = 0;
      player.player_directionRepeat = 1;
     tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulleftw,palette);
    tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulleftwa,palette);
    
    player.player_direction = 2; ////when movement ends player bitmap faces this direction paul rear
     player.player_y += 4;    ///move player y - 4 pixels 
     if(checkcolision())     
    {
     player.player_y -= 4;} ///causes player to stop when collision happens
     player.player_directionRepeat = 0;
    }
    if(player.player_y >= 224){
       player.player_y = 224;
  }
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
 if(y > 600 && last_y < 600 || ( 1 == player.player_directionRepeat && MoveRepeat >= MoveRepeatRate )){
    Serial.println(F("RIGHT")); ///UP
     MoveRepeat = 0;
      player.player_directionRepeat = 1;
     tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulrightw,palette);
    tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulright,palette);
    
    player.player_direction = 4;
    player.player_x += 4;
  if(checkcolision())
  {
    player.player_x -= 4;}
     player.player_directionRepeat = 0;
  }
  if(player.player_x <= 16){
      player.player_x = 16;
 }
 ////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////
if(!digitalRead(IRQ_PIN2)){
    uint32_t buttons = ss2.digitalReadBulk(button_mask2);
if (! (buttons & (1 << BUTTON_X))) {  /// BUTTON A RIGHT SIDE 
  state = STATE_Menu;             
  }
 }
 
///////////////////////////////////////////////////////////////////////////////     
//////////////////////////////PLAYER DIRECTION/////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
if (player.player_direction == 1){
  tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulrear,palette);
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
else if (player.player_direction == 2){
   tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulfront,palette);
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
else if (player.player_direction == 3){
    tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulleft,palette);
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
else if (player.player_direction == 4){
     tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulright,palette);
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////        
/////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////for use with movey blocks////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
else if (player.player_direction == 5){
     tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulrearwa,palette);
}     
else if (player.player_direction == 6){
     tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulfrontwa,palette);
}     
else if (player.player_direction == 7){
     tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulleftw,palette);
}          
else if (player.player_direction == 8){
     tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulrightw,palette); 
     }  
  }

Does any one have a clue why this is happening?
Fear is the mind killer.......

GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP

Duhjoker
Posts: 85
Joined: Mon Mar 20, 2017 8:09 am

Re: i2c analog joy stick glitches

Postby Duhjoker » Tue Jan 16, 2018 12:19 am

Anybody have any clues? Is it hardware or maybe using elapsed millis? I2C?
Fear is the mind killer.......

GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP

Who is online

Users browsing this forum: No registered users and 63 guests