Files
arduino_pong/arduino_pong.ino

65 lines
1.5 KiB
Arduino
Raw Normal View History

#include "Arduino_LED_Matrix.h"
2026-03-15 21:14:04 +01:00
#include "src/config.h"
#include "src/pong_render.h"
#include "src/pong_player.h"
#include "src/pong_ball.h"
// create LED matrix object
ArduinoLEDMatrix matrix;
2026-03-15 20:29:56 +01:00
// initial pong frame matrix
2026-03-15 17:07:03 +01:00
byte frame[MATRIX_HEIGHT][MATRIX_WIDTH] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
2026-03-15 20:29:56 +01:00
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
2026-03-14 21:35:19 +01:00
// players coordinates
int p1_start= 1;
int p2_start= 4;
2026-03-14 21:35:19 +01:00
// initials balls coordinates
int ball_x= BALL_RESET_X;
int ball_y= BALL_RESET_Y;
int need_refresh= 1;
2026-03-15 20:23:52 +01:00
int ball_delay= INITIAL_BALL_DELAY;
long exec_t2= millis();
2026-03-15 20:29:56 +01:00
void setup() {
Serial.begin(9600);
2026-03-15 20:29:56 +01:00
// start LED matrix
matrix.begin();
pinMode(P1_BTN_UP, INPUT_PULLUP);
pinMode(P1_BTN_BOTTOM, INPUT_PULLUP);
pinMode(P2_BTN_UP, INPUT_PULLUP);
pinMode(P2_BTN_BOTTOM, INPUT_PULLUP);
2026-03-15 20:29:56 +01:00
randomSeed(millis());
}
void loop() {
long exec_t1= millis();
pong_move_p1(p1_start, need_refresh);
pong_move_p2(p2_start, need_refresh);
2026-03-15 20:23:52 +01:00
if (exec_t1 - exec_t2 > ball_delay) {
move_ball(ball_x, ball_y, ball_delay, p1_start, p2_start, need_refresh);
exec_t2= exec_t1;
}
2026-03-15 20:23:52 +01:00
if (need_refresh) {
render_matrix(frame, p1_start, p2_start, ball_x, ball_y);
matrix.renderBitmap(frame, MATRIX_HEIGHT, MATRIX_WIDTH);
need_refresh= 0;
}
delay(50);
2026-03-14 21:35:19 +01:00
}