Set pixel in the world, not on the screen.

Post here to discuss all things DigiPixel related.

Moderators: Chuckt, Garth, bitfogav

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth

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

Post by ZephaniahNoah » Mon Sep 28, 2015 9:59 am

Haha! :D I took some parts off my Arduino for another project too.
DigiPixel is AWESOME! Image

User avatar
brad
Site Admin
Site Admin
Posts: 2576
Joined: Fri Mar 26, 2010 10:30 pm

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

Post by brad » Tue Sep 29, 2015 6:20 am

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 :)

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth

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

Post by ZephaniahNoah » Wed Sep 30, 2015 5:44 pm

No problem. Take your time.
DigiPixel is AWESOME! Image

User avatar
brad
Site Admin
Site Admin
Posts: 2576
Joined: Fri Mar 26, 2010 10:30 pm

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

Post by brad » Sat Oct 10, 2015 8:06 pm

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?

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth

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

Post by ZephaniahNoah » Tue Oct 13, 2015 6:15 pm

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.
DigiPixel is AWESOME! Image

User avatar
brad
Site Admin
Site Admin
Posts: 2576
Joined: Fri Mar 26, 2010 10:30 pm

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

Post by brad » Wed Oct 14, 2015 10:07 pm

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?

User avatar
bitfogav
Moderator
Moderator
Posts: 908
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

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

Post by bitfogav » Fri Oct 16, 2015 2:57 am

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.
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth

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

Post by ZephaniahNoah » Sat Oct 17, 2015 12:33 pm

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.
DigiPixel is AWESOME! Image

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth

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

Post by ZephaniahNoah » Sat Oct 17, 2015 12:37 pm

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.
DigiPixel is AWESOME! Image

User avatar
bitfogav
Moderator
Moderator
Posts: 908
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

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

Post by bitfogav » Sun Oct 18, 2015 6:24 am

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.
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth

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

Post by ZephaniahNoah » Sun Oct 18, 2015 6:43 am

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!
DigiPixel is AWESOME! Image

User avatar
bitfogav
Moderator
Moderator
Posts: 908
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

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

Post by bitfogav » Sun Oct 18, 2015 6:53 am

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. :)
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth

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

Post by ZephaniahNoah » Sun Oct 18, 2015 8:02 am

Yay! Thanks. I installed it successfully and getPixel works now!
DigiPixel is AWESOME! Image

User avatar
bitfogav
Moderator
Moderator
Posts: 908
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

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

Post by bitfogav » Sun Oct 18, 2015 8:44 am

That's great!!.. keep us updated on how you get on with you're game, I'll look forward to trying it out :)
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

User avatar
brad
Site Admin
Site Admin
Posts: 2576
Joined: Fri Mar 26, 2010 10:30 pm

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

Post by brad » Sun Oct 18, 2015 10:16 pm

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 :)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest