here is the code pls help i was making a ping pong game on a 8x8 matrix screen #include <Adafruit_GFX.h> #include <Adafruit_LEDBackpack.h>
Adafruit_8x8matrix matrix = Adafruit_8x8matrix();
// Ball position and direction
int ball_x = 3;
int ball_y = 3;
int ball_dx = 1;
int ball_dy = 1;
// Paddle position
int paddle_x = 0;
int paddle_y = 0;
void setup() {
matrix.begin(0x70); // Initialize the matrix display
matrix.setBrightness(15); // Set the brightness of the display (0-15)
randomSeed(analogRead(0)); // Seed the random number generator
}
Instead of doing that at the end of the loop, you could do this at the beginning:
void loop() {
static unsigned long lastLoopTime;
if (millis() - lastLoopTime < 50) return; // too soon to loop again
lastLoopTime = millis();
// original code below will run every 50 milliseconds.
which accomplish the same goal, but makes the frame rate consistent as long as all the calculations and stuff take less than 50 milliseconds.
It's a variation of the "blink without delay" pattern. I use it alla time for animations that want to run smoothly, like 10 ms gives a 100 Hz frame or "refresh" frequency.