[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 580: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 636: sizeof(): Parameter must be an array or an object that implements Countable
Brads Electronic Projects Forum • Set pixel in the world, not on the screen. - Page 2
Page 2 of 3

Re: Set pixel in the world, not on the screen.

Posted: Mon Sep 28, 2015 9:59 am
by ZephaniahNoah
Haha! :D I took some parts off my Arduino for another project too.

Re: Set pixel in the world, not on the screen.

Posted: Tue Sep 29, 2015 6:20 am
by brad
I do apologise for not getting around to this yet. I've had quite a busy few days!

But as soon as I can get some time i'll try it out :)

Re: Set pixel in the world, not on the screen.

Posted: Wed Sep 30, 2015 5:44 pm
by ZephaniahNoah
No problem. Take your time.

Re: Set pixel in the world, not on the screen.

Posted: Sat Oct 10, 2015 8:06 pm
by brad
Okay, I have finally managed to getting around to testing your game. It's a big world!

I should have asked this question before, but are you saying that when you go in the hut and press down on the rope that it does work as long as the code is not over 17,000 bytes? Or does it just not work all of the time no matter what the code size?

Have you experimented with comparing your players x/y co-ordinates with the data coming straight from the constant arrays (where the level data is stored) instead of using the getpixel function?

Re: Set pixel in the world, not on the screen.

Posted: Tue Oct 13, 2015 6:15 pm
by ZephaniahNoah
Yes, the code works if it's below about 17,000 bytes. As soon as I deleted some other code so that the total project consisted of 16,726 bytes, the getPixel function started working again. But when it was over 17,000 bytes, the getPixel function completely stopped working. Everything works except getPixel when the code is above 17,000 bytes approximately. Everything works, including getPixel, when the code is below 17,000 bytes.
Have you experimented with comparing your players x/y co-ordinates with the data coming straight from the constant arrays (where the level data is stored) instead of using the getpixel function?
I don't quite understand. What is the data from the constant arrays?

EDIT: Do you mean test ScreenYOffset & ScreenXOffset instead of using getPixel to test? At the very beginning of the game it tests the screen offset variables to see if you're on the button when you press B to open the first door. So that works but getPixel doesn't unless I delete some code to be under 17,000 bytes.

Re: Set pixel in the world, not on the screen.

Posted: Wed Oct 14, 2015 10:07 pm
by brad
I've looked into a few things with the memory problem but I just can't find anything that would be causing problems only when it goes above 17,000 bytes - since the Arduino Uno can go up to around 30,000 bytes.

With the constant arrays I'm talking about the arrays that hold your level data E.G.

Code: Select all

long MyDataRed[700]PROGMEM={0b00100001000000001000011111000000,
Here's the code for the GetPixel function:

Code: Select all

byte DigiPixel::getPixel(byte pixelX, byte pixelY){
	bitWrite(tempByte, 0, bitRead(bufferRed[pixelX], pixelY));
	bitWrite(tempByte, 1, bitRead(bufferGreen[pixelX], pixelY));
	bitWrite(tempByte, 2, bitRead(bufferBlue[pixelX], pixelY));
	bitWrite(tempByte, 3, bitRead(bufferBarriers[pixelX], pixelY));
	return tempByte;
}
Instead of using GetPixel, I'm wondering if you could check the mydatabarrier array to see if there are logic 1's there (or not) to then determine what you want to do in the game.

In response to your edit, You are exactly right - you would use your offset x and y co-ordinates to figure out which pixels to check in the constant array(s) in this case, really just your barrier array.

Does that make any sense?

Re: Set pixel in the world, not on the screen.

Posted: Fri Oct 16, 2015 2:57 am
by bitfogav
Can you post the code that doesn't work? Because I have tried your code you posted and added more to it and it runs with no problems, even over 17000 memory bytes.

Re: Set pixel in the world, not on the screen.

Posted: Sat Oct 17, 2015 12:33 pm
by ZephaniahNoah
Yea Brad, that makes sense. It's just convenient being able to just type digiPixel.getPixel(X,Y) and it's sad I won't be able to use it in this way. At least it I can use the screen offset.
bitfogav wrote:Can you post the code that doesn't work? Because I have tried your code you posted and added more to it and it runs with no problems, even over 17000 memory bytes.
That is the code that doesn't work. Did you press B or down on the rope? Or jump in the lava? Those two things use getPixel. The button uses ScreenOffset which does work above 17,000 bytes.

Re: Set pixel in the world, not on the screen.

Posted: Sat Oct 17, 2015 12:37 pm
by ZephaniahNoah
Aha! I was wrong! When I deleted some code I came to the assumption that it was the amount of code that caused the problem. But it was the code I deleted that was the problem. Here's the code:

Code: Select all

                   //BUTTON! \/
void button(){
  if (-ScreenYOffset+ButtonY > -1){
    digiPixel.setPixel(-ScreenXOffset+ButtonX,-ScreenYOffset+ButtonY,ButtonColor);
  }
  if (ScreenXOffset < 24){
    if (digiPixel.buttonBPressed){
      if (ScreenYOffset == 23 & ScreenXOffset == 2){
        ButtonColor = 10;
        ButtonPress = true;
      }
    }
  }
}
                   //DOOR! \/
void door(){
  if (ButtonPress == false){
    if (-ScreenYOffset+DoorY > -1){
      digiPixel.setPixel(-ScreenXOffset+DoorX,-ScreenYOffset+DoorY,13);
    }
    if (-ScreenYOffset+DoorY > -1){
      digiPixel.setPixel(-ScreenXOffset+DoorX,-ScreenYOffset+DoorY-1,13);
    }
  }
}
When I delete this code, plus button and door in void loop, getPixel works again. Any idea why this would cause getPixel to fail? I'm curios to see why it worked for bitfogav.

EDIT: Also I mentioned earlier when I added the download that I use Arduino 1.0.6. But the reason for that is because I had troubles getting the DigiPixel libraries working with newer versions. And I wonder if bitfogav is using a newer version of Arduino. Or maybe uses a Digispark or other Arduino campatable microcontroller. Anyways, I really want to get to working on this again. I'll be experimenting with my code and different versions of Arduino.

Re: Set pixel in the world, not on the screen.

Posted: Sun Oct 18, 2015 6:24 am
by bitfogav
ZephaniahNoah wrote:
bitfogav wrote:Can you post the code that doesn't work? Because I have tried your code you posted and added more to it and it runs with no problems, even over 17000 memory bytes.
That is the code that doesn't work. Did you press B or down on the rope? Or jump in the lava? Those two things use getPixel. The button uses ScreenOffset which does work above 17,000 bytes.
When I come to the red hut I then push down to go down the rope (with no issues), button B doesn't seem to do anything when I'm at the rope?. I then come to the lava and fall into the lava and the game resets. is this not correct??.
ZephaniahNoah wrote:Aha! I was wrong! When I deleted some code I came to the assumption that it was the amount of code that caused the problem. But it was the code I deleted that was the problem. Here's the code:

EDIT: Also I mentioned earlier when I added the download that I use Arduino 1.0.6. But the reason for that is because I had troubles getting the DigiPixel libraries working with newer versions. And I wonder if bitfogav is using a newer version of Arduino. Or maybe uses a Digispark or other Arduino campatable microcontroller. Anyways, I really want to get to working on this again. I'll be experimenting with my code and different versions of Arduino.
I saw you was using the old classic version 1.0.6 arduino, I am testing you're code using the latest Arduino IDE version 1.6.5, I have had no problems importing the digipixel library into this version.
There was only one change I had to make to you're code to work with version 1.6.5 and that was to list the programme memory arrays to "const".
From:

Code: Select all

long MyDataRed[700]PROGMEM={0b00100001000000001000........etc
To:

Code: Select all

const long MyDataRed[700]PROGMEM={0b00100001000000001000.......etc
And I am also using an Arduino Uno board which use's the Atmega382p chip.

Re: Set pixel in the world, not on the screen.

Posted: Sun Oct 18, 2015 6:43 am
by ZephaniahNoah
bitfogav wrote:When I come to the red hut I then push down to go down the rope (with no issues), button B doesn't seem to do anything when I'm at the rope?. I then come to the lava and fall into the lava and the game resets. is this not correct??.
No, that is correct. I guess I'll try the new Arduino. I hope this works!

Re: Set pixel in the world, not on the screen.

Posted: Sun Oct 18, 2015 6:53 am
by bitfogav
If you need help installing the digipixel library after updating to the latest Arduino IDE then you can find more info here
https://www.arduino.cc/en/Guide/Libraries#toc2
I normally just put the digipixel folder (unzipped) into the Arduino library folder and restart the Arduino IDE if you have the IDE already running?.

if your using a windows PC then usually you're find the Arduino library folder in "My Documents" under Arduino>libraries. :)

Re: Set pixel in the world, not on the screen.

Posted: Sun Oct 18, 2015 8:02 am
by ZephaniahNoah
Yay! Thanks. I installed it successfully and getPixel works now!

Re: Set pixel in the world, not on the screen.

Posted: Sun Oct 18, 2015 8:44 am
by bitfogav
That's great!!.. keep us updated on how you get on with you're game, I'll look forward to trying it out :)

Re: Set pixel in the world, not on the screen.

Posted: Sun Oct 18, 2015 10:16 pm
by brad
Sorry for being late to reply here again and great job there bitfogav!

I apologise for being away but I've been quite busy getting things all organised for the DigiRule Kickstarter campaign.

Great to hear it is working and as bitfogav said, let us know how it is going for you :)