rodot wrote:You shouldn't use delay as it blocks everything happening in the background (in gb.update() actually) : sound, backlight, battery monitoring, buttons, etc, so you Gamebuino will be completely unresponsive for the duration of the delay. For example the user won't be able to skip the dialog or to get back to the menu.
[...]
Ah, right, I noticed that during writing of the engine of the RPG project thing. However, I couldn't use the other function stuff because of __reasons__ so I wrote a thing where it updates sound inside the interrupt, i already ran custom button code and it wouldn't be too noticable for backlight / battery monitoring to not be updated in a bit.
The all-interrupt sound thing can be found
here, in case you are interested
noah wrote:Yeah it is, thanks. I never worked out what micro and milliseconds actually accounted for in terms of a second, but delay(1000) make it pause for 1 second. I guess that's milliseconds?
Micro and milli are actually super easy! (Thanks metric system!)
Micro --> 10^(-6)
Milli --> 10^(-3)
Or, like, if you have 12345 milliseconds that's the same as 12.345 seconds (just move the comma left by three)
If you have 12345 microseconds that's the same as 0.012345 seconds (just move the comma left by six)
Calculations in the other direction are just about moving the coma into the other direction ^.^
noah wrote:well... that didn't work. I looked at the example but that shows a blink.
I tried
- Code: Select all
void loop(){
if(gb.update()){
if(gb.frameCount < 40){
blah blah
}else if(gb.frameCount < 80){
blah blah
}
}
}
...but this didn't work, I'm assuming because I stayed more than two seconds on the title screen. What is the best way of implementing this, I just wanted a wait?!
The thing is that gb.frameCount returns the current frame count which is keep on increasing since the beginning of tiiiiime! (the program)
Here's a little example, which is untested, though:
- Code: Select all
void wait(byte frames){
gb.frameCount = 0; // reset the framecount
while(gb.frameCount < frames){ // repeat the next until the framecount is equal to how many frames we want to wait
while(!gb.update()); // wait until things need updating
// right here you would put things to update the screen, if it got erased, that is (configurable via gb.display.persistence )
}
}
That would however destroy the frame count, for without destroying something like this might work:
- Code: Select all
void wait(int frames){
frames += gb.frameCount;
while(gb.frameCount < frames){
while(!gb.update());
}
}
However I don't know how well that handles with int-overflows