Storing images or image data on SD (gaming)

Status
Not open for further replies.
They have adapters for teensy 3.2 and i think they once produced a teensy feather. But don't quote me. Its a neat set up though. I made a wooden case for mine.

ok so heres the deal I made this set up which works and only outputs when a button or direction is placed.
Code:
  int x = ss1.analogRead(2);
  int y = ss1.analogRead(3);
  
  if ( (abs(x - last_x) > 3)  ||  (abs(x + last_x) < 3) || (abs(y - last_y) > 3) || (abs(y + last_y) < 3)) {
    Serial.print(x); Serial.print(", "); Serial.println(y);
    last_x = x;
    last_y = y;
  }
  
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  int x1 = ss2.analogRead(2);
  int y1 = ss2.analogRead(3);

   if ( (abs(x1 - last_x2) > 3)  ||  (abs(x1 + last_x2) < 3) || (abs(y1 - last_y2) > 3) || (abs(y1 + last_y2) < 3)) {
    Serial.print(x); Serial.print(", "); Serial.println(y);
    last_x2 = x1;
    last_y2 = y1;
  }

but when I separate them out to different functions like so it goes haywire constantly throwing up left right up or down in the serial monitor.
Code:
 int x = ss1.analogRead(2);
 int y = ss1.analogRead(3);
 
 if ( (abs(x - last_x) > 3)){
  Serial.print("left1");
   last_x = x;
 }

  if ( (abs(x + last_x) < 3)){
  Serial.print("right1");
   last_x = x;
 }
 
 if ( (abs(y - last_y) < 3)){
  Serial.print("down1");
   last_y = y;
 }
  if ( (abs(y + last_y) > 3)){
  Serial.print("up1");
   last_y = y;
 }
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/* int x2 = ss2.analogRead(2);
 int y2 = ss2.analogRead(3);

 if ( (abs(x2 - last_x2) > 3)){
  Serial.print("left2");
   last_x2 = x2;
 }

  if ( (abs(x2 + last_x2) < 3)){
  Serial.print("right2");
   last_x2 = x2;
 }
 
 if ( (abs(y2 - last_y2) < 3)){
  Serial.print("down2");
   last_y2 = y2;
 }
  if ( (abs(y + last_y) > 3)){
  Serial.print("up2");
   last_y2 = y2;
 }*/

WTH??!!!!
 
i would imagine it would, since the value is always changing and never exact, it will always be higher or lower than 3, which will trigger a print. usually last values are for numbers that dont change (or dont change much)

in my opinion i would keep the original function as is as its more compressed, less code space used, and i can only have a hunch the x values, by looking at the top code, are set when the y values are triggered as well, which your second code below doesnt account for

seriously though, i cant believe your not using the analog channels on teensy, its as easy as ommitting the ss1. and just using analogRead(2) for pin 2 :) im sure the teensy has a better ADC than that i2c board

just a thought
 
Last edited:
I don't understand enough what abs or the analog is doing in order to fix it. I was trying to make it if x -3 and greater than 3 do function. every thing I do just gives me constant string. And really cant see away to use the original function with functions in them

Code:
 int x = ss1.analogRead(2);
 int y = ss1.analogRead(3);
 
      if ( (abs(x - 3) > 3)){
  Serial.print("left1");
 }
else  if ( (abs(x + 3) < 3)){
  Serial.print("right1");
 }
      if ( (abs(y - 3) > 3)){
  Serial.print("down1");
 }
else  if ( (abs(y + 3) < 3)){
  Serial.print("up1");
 }
 
Quick search finds this in the Arduino Reference :: abs() - Calculates the absolute value of a number.
That is whatever the result of (x-3) is it will be positive - even if x is less than 3 to begin with.

tonton81 suggesting to use Teensy native analog pins if you have any open {and they max at 3.3V or less) would greatly simplify things - over dealing with i2c based overhead that may end up with a lesser quality ADC result.
 
hes going from an esp to a teensy, he definately has tons more than what that board can offer, that board is just a bandage for tiny micros that lack peripheral/gpios, and kinda like an anchor if teensy is a boat. /rant over :p
 
duhjoker, adafruit seems to follow the functions similar to the core, it wouldnt be hard to convert it to run on teensy itself and you wouldnt need that board, just by removing all the “ss1.” and “ss2.” from the function calls and you have the 3.3v analogs connected to those teensy pins, you should be all set, teensy has tons of analog pins so you dont even need 2 two boards
:)
Tony
 
ICK - ESP dual support - I thought that went away months back to focus on a single - and perhaps ideal - platform ... Getting it to work on Teensy . . .
 
I get what your saying guys but I just don't have the room for soldering extra pins or the wiring it would take. kinda got every thing packed tight into a little case.

There's actually another example included in the seesaw library I had not checked out. Joy wing oled example that prints a triangle when the stick is moved. But it doubles each x and y move. I think its saying if stick is moved left print white triangle if released paint the triangle black.

Code:
int last_x = 0, last_y = 0;
void loop() {
  int y = ss.analogRead(2);
  int x = ss.analogRead(3);

  if(x > 600 && last_x < 600){
    tft.fillTriangle(120, 30, 120, 50, 110, 40, ST7735_WHITE);
    Serial.println(F("LEFT"));
  }
  else if(last_x > 600 && x < 600){
    tft.fillTriangle(120, 30, 120, 50, 1.10, 40, ST7735_BLACK);
  }
  
  if(x < 400 && last_x > 400){
    tft.fillTriangle(150, 30, 150, 50, 160, 40, ST7735_WHITE);
    Serial.println(F("RIGHT"));
  }
  else if(last_x < 400 && x > 400){
    tft.fillTriangle(150, 30, 150, 50, 160, 40, ST7735_BLACK);
  }
  
  if(y > 600 && last_y < 600){
    tft.fillTriangle(125, 26, 145, 26, 135, 16, ST7735_WHITE);
    Serial.println(F("DOWN"));
  }
  else if(last_y > 600 && y < 600){
    tft.fillTriangle(125, 26, 145, 26, 135, 16, ST7735_BLACK);
  }
  
  if(y < 400 && last_y > 400){
    tft.fillTriangle(125, 53, 145, 53, 135, 63, ST7735_WHITE);
    Serial.println(F("UP"));
  }
  else if(last_y < 400 && y > 400){
    tft.fillTriangle(125, 53, 145, 53, 135, 63, ST7735_BLACK);
  }

  if ( (abs(x - last_x) > 3)  ||  (abs(y - last_y) > 3)) {  //////// is this still needed?
    Serial.print(x); Serial.print(", "); Serial.println(y);
    last_x = x;
    last_y = y;
  }

do I need the second part of each movement. if so how do I say do nothing? Do I still need the last part?
 
Remove the second part of each movement and the last part as seen below and it runs stable....

Code:
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/////////// board rotation = 270* 
 int y = ss1.analogRead(2);
  int x = ss1.analogRead(3);

  if(x > 600 && last_x < 600){
    Serial.println(F("UP")); ///LEFT
  }
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////  
  if(x < 400 && last_x > 400){
    Serial.println(F("DOWN"));  ////RIGHT
  }
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////  
  if(y > 600 && last_y < 600){
    Serial.println(F("RIGHT"));   ///DOWN
  }
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////  
  if(y < 400 && last_y > 400){
    Serial.println(F("LEFT")); ///UP
  }
    last_x = x;
    last_y = y;
 
all right so I got the new analog controls and buttons programmed in to my game example. But I cant figure out to make the joystick movement repeat. I can only move my player object once per stick movement which doesn't work at all. Any clue as to how I can make the analog movements repeat when the stick is held in a direction?

the comments with directions are because I have the joys rotated 90 and 270 degrees so the directions had to adjusted for the rotation of the joy boards

Code:
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////  if(tft.Brepeat(BTN_UP,1)){
 int y = ss1.analogRead(2);
  int x = ss1.analogRead(3);

  if(x > 600 && last_x < 600){
     Serial.println(F("UP")); ///LEFT
      tft.writeRectNBPP(player.player_x, player.player_y,  16, 16, 4, paulrearwa, palette);
      tft.writeRectNBPP(player.player_x, player.player_y, 16, 16, 4, paulrearwb, palette);
      
     player.player_direction = 1;
     player.player_y -= 4;
     if(checkcolision())
    {
     player.player_y += 4;} 

    }
     if(player.player_y <= 16){
        player.player_y = 16;}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////  
  if(x < 400 && last_x > 400){
    Serial.println(F("DOWN")); ///RIGHT
    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;
    player.player_y += 4;
    if(checkcolision())
    {
       player.player_y -=4;}
       
    }
    if(player.player_y >= 224){
       player.player_y = 224;}
  
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////  
  if(y < 400 && last_y > 400){
    Serial.println(F("RIGHT"));   ///DOWN
     tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulleftw,palette);
    tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulleft,palette);
    
    player.player_direction = 3;
    player.player_x -= 4;
    if(checkcolision())
   {
      player.player_x += 4;} 
   }
   if(player.player_x >= 304){
      player.player_x = 304;}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////  
 if(y > 600 && last_y < 600){
    Serial.println(F("LEFT")); ///UP
     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;}
    
     
  }
   if(player.player_x <= 16){
      player.player_x = 16;}
      
    last_x = x;
    last_y = y;
  
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////if(tft.Bpressed(BTN_A)){
 if(!digitalRead(IRQ_PIN2)){
    uint32_t buttons = ss2.digitalReadBulk(button_mask2);
if (! (buttons & (1 << BUTTON_X))) {  /// BUTTON A RIGHT SIDE 
  state = STATE_Menu;             
  }
 }
 
Not seeing how the analog works - but it looks like player can move only one direction at a time?

After each pass these take away the detection of change or player 'intent': last_x = x; last_y = y;

When you do any accept of direction change and set one of: player.player_direction = 4;

Perhaps an "elapsedMillis MoveRepeat;' time base and another tracking variable when any case like this is detected: if(y > 600 && last_y < 600){

When a move transition is detected:
player.player_directionRepeat = 4; // or whatever direction 1,2,3,4 - and it will need set to 0 when the joystick drops below the threshold!
MoveRepeat = 0;

Then something like:
Code:
#define MoveRepeatRate 100 // set this for how long in milis to wait for auto repeat move
elapsedMillis MoveRepeat;

  // Update Player position here as needed for game play - [B]this added to each direction case[/B] where it is handled 
if ( (y > 600 && last_y < 600) || ( 4 == player.player_directionRepeat && MoveRepeat >= MoveRepeatRate )) {
  MoveRepeat = 0;
  player.player_directionRepeat = 4;
  // update player as before ...
}
 
Last edited:
Well yea the player can only move one direction at a time.

heres a break down of my player movement....

Code:
 int y = ss1.analogRead(2);   // reads analog input y
  int x = ss1.analogRead(3);  // reads analog input x

       if(x > 600 && last_x < 600){  ////if x is greater than 600 and last x was less than 600 do something
 Serial.println(F("UP")); ///LEFT 
      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

    }
     if(player.player_y <= 16){    ////keeps player from walking off the screen. 
        player.player_y = 16;}

it uses pwm from what I understand of the see saw library
 
by 'not seeing' - I meant - not looking that close - but it seems I got the right gist ...

So for that direction = 1 the code change could be something like this:

Code:
// Add this element set to 0 to start
player.player_directionRepeat = 0;  // Zero to start and reset to zero anytime no movement was requested

 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 
[B]      MoveRepeat = 0;
      player.player_directionRepeat = 1;
[/B]      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
     [B]player.player_directionRepeat = 0;[/B]
    }
    if(player.player_y <= 16){    ////keeps player from walking off the screen. 
        player.player_y = 16;
    }
  }
 
ok so I changed my player to match the stuff you added but I get no change....

Code:
  int y = ss1.analogRead(2);
  int x = ss1.analogRead(3);
  int player_directionRepeat = 0;  // Zero to start and reset to zero anytime no movement was requested
  int MoveRepeat = 0;
  #define MoveRepeatRate 100 // set this for how long in milis to wait for auto repeat move
  elapsedMillis MoveRepeat;
  player_directionRepeat = 0;
////////////////////////////////////////////////////////////////////////////////////////////////////
  player_directionRepeat = 0;  // Zero to start and reset to zero anytime no movement was requested

 if(x > 600 && last_x < 600 || ( 1 == 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_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_directionRepeat = 0;
    }
    if(player.player_y <= 16){    ////keeps player from walking off the screen. 
        player.player_y = 16;
    }

shouldn't this part get the repeat since it is what moves the player? Calling player_direction places a bitmap on the screen as the bitmap showing when player has stopped

player.player_y -= 4; ///move player y - 4 pixels

or are you telling the stick to repeat?



edit::::

I'm on it
 
Last edited:
I don't know how to read that code snippet? Not sure it could have compiled as there are two vars named MoveRepeat:
int MoveRepeat = 0;
elapsedMillis MoveRepeat;

Only the second should be present - and it needs to be defined outside loop().

Likewise 'player_directionRepeat = 0;' should not be inside loop() - but she be added to the player struct and set 0 to begin with

I altered the if() conditions so they should stop repeating without having to always set player.player_directionRepeat=0;

Code:
#define MoveRepeatRate 100 // set this for how long in milis to wait for auto repeat move
elapsedMillis MoveRepeat;


loop() {
  // Update Player position here as needed for game play - this added to each direction case where it is handled 
  if ( (y > 600 ) && ( ( last_y < 600) || ( 4 == player.player_directionRepeat && MoveRepeat >= MoveRepeatRate ) ) ) {
    MoveRepeat = 0;
    player.player_directionRepeat = 4;

    [B]// update player as before ...[/B]
  }

 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
    }
    if(player.player_y <= 16){    ////keeps player from walking off the screen. 
        player.player_y = 16;
    }
  }
 
ok I don't get it. I can get up to work but but if i repeat the variables given i get nothing but up.

Code:
struct Player
{
  int player_x; 
  int player_y; 
  int room;
  int player_direction; 
  int player_directionRepeat;
};

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

  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
  elapsedMillis MoveRepeat;
////////////////////////////////////////////////////////////////////////////////////////////////////

 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;
    player.player_y += 4;
    if(checkcolision())
    {
       player.player_y -=4;}
       player.player_directionRepeat = 0;
    }
    if(player.player_y >= 224){
       player.player_y = 224;
 }
 
Posted code snippet isn't clear?

That covers just two directions of movement - but AFAIK they should work. The way I re-coded it last it should work dropping player.player_directionRepeat and just replacing it with player.player_direction, but that won't break it.

Try to figure out where I'm going with this and fix it as needed - do the same for the other two directions - but you might work to get one working first. Once the user direction is determined it will continue that way after each MoveRepeatRate millis, as long as the joystick is still held that way. As soon as it drops below the test threshold it will stop - or go the new direction. Only problem might be holding on a diagonal based on the order of the testing for the direction.

Looking at these lines I have the questions in the comment:
int y = ss1.analogRead(2); // << This should be in loop - is it ?
int x = ss1.analogRead(3); // << This should be in loop - is it ?
#define MoveRepeatRate 100 // set this for how long in milis to wait for auto repeat move
elapsedMillis MoveRepeat; // << This should NOT be in loop - is it ?
 
now i have everything but left going but there is a glitch. the player only moves up or right til the menu pops up then down can be accessed but no left.

ive been staring at it for a while and i just don't see it. Yes int y = ss1.analogRead(2); and int x = ss1.analogRead(3); are in the loop. i left repeat rate at 100 seems do to do fine when right up and down are pushed. I have removed the elapsedmillis from the loop and placed in the same file out side the loop.

player structure

Code:
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};

and here is the function...

Code:
elapsedMillis MoveRepeat;

void drawplayer() {
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
  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
///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// 
 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")); ///LEFT 
     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,paulleft,palette);

      player.player_direction = 3;
    player.player_x -= 4;
  if(checkcolision())
  {
    player.player_x += 4;}
     player.player_directionRepeat = 0;
  }
   if(player.player_x >= 304){
      player.player_x = 304;
}  
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
 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); 
     }  
  }

all but left works. i ran some serial prints and tested the directions using the seesaw example and all works. in my game left never prints out but right and up down work but only after bringing up the menu and closing it
 
That is some progress - at a glance it looks about like I pictured it. I'll put it in the IDE to view it better than in a tiny scrolling block and parenthesis matching ... and be back.

I don't have any idea why 'menu' activation would impact these statements - does it have any effect on the values in the if()'s?

Seeing that player_direction can be 5,6,7,8 says that the added player.player_directionRepeat will be required as I see it.

#defines are ugly and stupid - but have value - worse when hidden : that one should be outside the function where it can be seen with the elapsedMillis perhaps.

Sometimes I guess wrong on the order of precedence like in that if() - or it may be right until I add one more thing and then it blows up :( It is best to be explicit with too many paired parenthesis sets than one too few. I think there may have a problem there and one I gave was eliminated.

My intent was this for all four:

if ( (x < 400) && ( (last_x > 400) || ( 1 == player.player_directionRepeat && MoveRepeat >= MoveRepeatRate ) ) ){
 
These are wrong and will undo the work done to track repeat movement requests.

Code:
    if (checkcolision())
    {
      player.player_x += 4;
    }
[B]    player.player_directionRepeat = 0;[/B]

They all should be:

Code:
    if (checkcolision())
    {
      player.player_x += 4;
[B]      player.player_directionRepeat = 0;
[/B]    }
 
In all four cases what is in the checked with "== player.player_directionRepeat" in the if MUST match what is set within the if() for player.player_direction AND player.player_directionRepeat:

This should have all of the above items fixed for "DOWN" which is commented as "///LEFT"
> added parenthesis to if()
> properly set and test : player.player_directionRepeat for "2" in this case
> Properly unset player.player_directionRepeat =0 on collision
> Did a Ctrl+T in IDE before posting code to get uniform indenting

Code:
  if ( (x < 400) && ( (last_x > 400) || ( 2 == player.player_directionRepeat && MoveRepeat >= MoveRepeatRate ) ) ) {
    Serial.println(F("DOWN")); ///LEFT
    MoveRepeat = 0;
    player.player_directionRepeat = 2;
    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;
      player.player_directionRepeat = 0;
    } ///causes player to stop when collision happens
  }
 
the direction thig is mixed up due to the rotation of the joys on the console. ones turned 90* the other270*. Ok i once again checked that the board was working properly using the adafruit example. They both work. I changed every thing to resemble the above but no change. If i use my original code everything works but the player moves once per stick move. But it all works before and after the menu is accessed.

I just tested left by itself but nothing not even the call to serial print left when its pushed left.
Code:
   if((y < 400) && ( (last_y > 400) || ( 2 == player.player_directionRepeat && MoveRepeat >= MoveRepeatRate ))){
    Serial.println(F("LEFT")); ///DOWN 
     MoveRepeat = 0;
      player.player_directionRepeat = 2;
     tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulleftw,palette);
    tft.writeRectNBPP(player.player_x, player.player_y,16,16,4,paulleft,palette);
    
    player.player_direction = 3; ////when movement ends player bitmap faces this direction paul rear
     player.player_x -= 4;    ///move player y - 4 pixels 
     if(checkcolision())     
    {
     player.player_x += 4; ///causes player to stop when collision happens
     player.player_directionRepeat = 0;
    }
   }
    if(player.player_x >= 304){
       player.player_x = 304;
  }


just as an experiment just now i uncoomented a one at a time left and changed it over. i wont work. so i did the same thing with right. only works after menu. This is driving me crazy. i really don't get why the menu has an effect on using the down shift of the stick


edit:::

just flipped the screen rotation 180* and used the other stick and no change. same weird behavior. then rechecked with the adafruit example and that works.
 
Last edited:
Could the problem be with the pwm out puts paired with the timer? PWM as I understand it is a timed pulse, the longer the push the longer the pulse is. Could it be the elapsed millis commands messing with the pwm timers?
 
With the analog values read from an external device - what they return and when is a mystery. If it works right with the base example ( adafruit? ) - it should work the same unless something is changed as implemented.

Add on of the tests to the adafruit example to see it work?
 
Hey Duhjoker, do you have a complete code listing someplace? On GitHub? Maybe I could upload it to my teensy with the two joy feather wings connected and see what's up. I'm having a hard time piecing together the current state of your code from individual forum posts.
 
Status
Not open for further replies.
Back
Top