I was coding a MineSweeper game (In C), and I wanted to add a fade effect in the background by adjusting the pallet colors, which I ran using the code below. It worked fine while plugged into my computer and the fade effect went at a slower speed as I intended. Once I unplugged my calculator, the fade effect went crazy and started flashing through all of them in half a second. Plugging in the calculator again showed the slower fade, but at varying speeds each time, going faster or slower than what I intended for the fade to take.
Why does this happen? and is there a way to get timers or something similar to work to display the "Fading" effect consistently. I don't check the battery in the code, and this still happens when I plug the calculator into a wall outlet instead of a computer.
Code:
Video showing the Fading effect being affected by plugging or unplugging the Calculator (Using version 5.4):
Why does this happen? and is there a way to get timers or something similar to work to display the "Fading" effect consistently. I don't check the battery in the code, and this still happens when I plug the calculator into a wall outlet instead of a computer.
Code:
#include <math.h>
#include <ti/getcsc.h>
#include <keypadc.h>
#include <stdio.h>
#include <stdlib.h>
...
unsigned char cycle = 0;
unsigned char delay = 0;
char pause = 0;
while (key != 49) { //Key 49 or F5 quits the game
do {
key = os_GetCSC();
delay++;
if (delay > 24) { //Waits for 24 loops to pass
if (pause < 0) {
unsigned short *fP = (int*)0xE30200; //Memory address of pallet
unsigned short bright[7] = {528,495,462,429,396,363,330};
fP = fP + (cycle / 13) + 18; //Sets color pallet 18,19,20, or 21
if (cycle % 13 < 7) {
*fP = bright[cycle % 13]; //Goes from 330 to 528
} else {
*fP = bright[12 - (cycle % 13)]; //Goes from 528 to 330
}
cycle = (cycle + 1) % 56; //Repeats after running 56 times
if (cycle % 13 == 7) {
pause = 20; //Pauses for 20 "Loops" (Showing a symbol)
} else if (cycle % 13 == 0) {
pause = 8; //Pauses for 8 "Loops" (Showing nothing)
}
}
pause--;
delay = 0; //Resets the delay thing
}
} while(!key);
//Code related to key presses and game logic
}
Video showing the Fading effect being affected by plugging or unplugging the Calculator (Using version 5.4):