reduce input lag using millis for matrix render
This commit is contained in:
@@ -35,6 +35,7 @@ int apple_x= 9;
|
|||||||
int apple_y= 3;
|
int apple_y= 3;
|
||||||
|
|
||||||
int loop_delay= 300;
|
int loop_delay= 300;
|
||||||
|
long exec_t2= millis();
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
//Serial.begin(115200);
|
//Serial.begin(115200);
|
||||||
@@ -165,10 +166,15 @@ void change_direction() {
|
|||||||
else if (l == LOW && direction != 'r') direction= 'l';
|
else if (l == LOW && direction != 'r') direction= 'l';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
show_apple();
|
long exec_t1= millis();
|
||||||
change_direction();
|
change_direction();
|
||||||
matrix.renderBitmap(frame, 8, 12);
|
if (exec_t1 - exec_t2 > loop_delay) {
|
||||||
move_snake();
|
show_apple();
|
||||||
delay(loop_delay);
|
move_snake();
|
||||||
|
matrix.renderBitmap(frame, 8, 12);
|
||||||
|
exec_t2= exec_t1;
|
||||||
|
}
|
||||||
|
delay(50);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user