Compare commits
6 Commits
2727dfb0ef
...
v1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8906b2eab5 | ||
|
|
5b94e21f21 | ||
|
|
8a7bd2b192 | ||
|
|
487756978f | ||
|
|
bf2b794421 | ||
|
|
f0e8a7f05f |
35
.github/workflows/cd.yml
vendored
Normal file
35
.github/workflows/cd.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
name: Arduino Pong CD
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Arduino CLI
|
||||
run: |
|
||||
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
|
||||
echo "$HOME/bin" >> $GITHUB_PATH
|
||||
|
||||
- name: Install Board Core and Libs
|
||||
run: |
|
||||
arduino-cli core update-index
|
||||
arduino-cli core install arduino:renesas_uno
|
||||
arduino-cli lib install "Arduino_LED_Matrix"
|
||||
|
||||
- name: Build Binary
|
||||
run: make compile
|
||||
|
||||
- name: Create Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: |
|
||||
build/arduino.renesas_uno.unor4wifi/arduino_pong.ino.bin
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@@ -4,7 +4,7 @@ on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
paths:
|
||||
- 'arduino_pong.ini'
|
||||
- 'arduino_pong.ino'
|
||||
- 'Makefile'
|
||||
- '.github/workflows/ci.yml'
|
||||
|
||||
@@ -34,4 +34,4 @@ jobs:
|
||||
|
||||
- name: Compile Sketch (via Makefile)
|
||||
shell: bash
|
||||
run: make compile
|
||||
run: make prepare_and_compile
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1,3 @@
|
||||
.secrets
|
||||
.arduino_cache/
|
||||
bin/
|
||||
|
||||
52
Makefile
52
Makefile
@@ -1,20 +1,58 @@
|
||||
PORT ?= /dev/ttyACM0
|
||||
BOARD = arduino:renesas_uno:unor4wifi
|
||||
SKETCH = arduino_pong.ino
|
||||
CACHE_DIR = $(shell pwd)/.arduino_cache
|
||||
BIN_DIR = $(shell pwd)/bin
|
||||
CLI = $(BIN_DIR)/arduino-cli --config-file $(CACHE_DIR)/arduino-cli.yaml
|
||||
|
||||
YELLOW := \033[0;33m
|
||||
GREEN := \033[0;32m
|
||||
CLEAR := \033[0m
|
||||
|
||||
prepare:
|
||||
@mkdir -p $(BIN_DIR)
|
||||
@mkdir -p $(CACHE_DIR)
|
||||
@if [ ! -f $(BIN_DIR)/arduino-cli ]; then \
|
||||
echo -e "📥 $(YELLOW)Downloading arduino-cli...$(CLEAR)"; \
|
||||
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=$(BIN_DIR) sh; \
|
||||
fi
|
||||
@if [ ! -f $(CACHE_DIR)/arduino-cli.yaml ]; then \
|
||||
echo -e "⚙️ $(YELLOW)Initializing local config...$(CLEAR)"; \
|
||||
$(CLI) config init --dest-dir $(CACHE_DIR); \
|
||||
$(CLI) config set directories.data $(CACHE_DIR)/data; \
|
||||
$(CLI) config set directories.downloads $(CACHE_DIR)/downloads; \
|
||||
$(CLI) config set directories.user $(CACHE_DIR)/user; \
|
||||
fi
|
||||
@if ! $(CLI) core list | grep -q "arduino:renesas_uno"; then \
|
||||
echo -e "$(YELLOW)📥 Installing board core...$(CLEAR)"; \
|
||||
$(CLI) core update-index; \
|
||||
$(CLI) core install arduino:renesas_uno; \
|
||||
fi
|
||||
|
||||
compile:
|
||||
arduino-cli compile -b $(BOARD) $(SKETCH)
|
||||
@echo -e "$(GREEN)🛠️ Compiling $(SKETCH)...$(CLEAR)"
|
||||
@$(CLI) compile -b $(BOARD) $(SKETCH)
|
||||
|
||||
prepare_and_compile:
|
||||
make prepare --no-print-directory
|
||||
make compile --no-print-directory
|
||||
|
||||
upload:
|
||||
arduino-cli upload -b $(BOARD) -p $(PORT)
|
||||
@echo -e "$(GREEN)🚀 Uploading $(SKETCH)...$(CLEAR)"
|
||||
@$(CLI) upload -b $(BOARD) -p $(PORT)
|
||||
|
||||
upload_verbose:
|
||||
arduino-cli upload -b $(BOARD) -p $(PORT) -v
|
||||
@echo -e "$(GREEN)🚀 Uploading (Verbose) $(SKETCH)...$(CLEAR)"
|
||||
@$(CLI) upload -b $(BOARD) -p $(PORT) -v
|
||||
|
||||
monitor:
|
||||
arduino-cli monitor -p $(PORT)
|
||||
@$(CLI) monitor -p $(PORT)
|
||||
|
||||
run:
|
||||
make compile
|
||||
make upload
|
||||
make monitor
|
||||
make compile --no-print-directory
|
||||
make upload --no-print-directory
|
||||
make monitor --no-print-directory
|
||||
|
||||
run_init:
|
||||
make prepare --no-print-directory
|
||||
make run --no-print-directory
|
||||
|
||||
@@ -57,9 +57,11 @@ This project includes a `Makefile` to automate the workflow using `arduino-cli`.
|
||||
### Commands
|
||||
| Command | Description |
|
||||
| :--- | :--- |
|
||||
| `make prepare` | Downloads arduino-cli locally and installs the UNO R4 core. |
|
||||
| `make compile` | Compiles the sketch without uploading. |
|
||||
| `make upload` | Uploads the compiled binary to `/dev/ttyACM0`. |
|
||||
| `make monitor` | Opens the Serial Monitor. |
|
||||
| `make run` | Full cycle: Compile + Upload + Monitor. |
|
||||
| `make run_init` | Full first-time setup: Prepare env + Compile + Upload + Monitor. |
|
||||
|
||||
> **Note:** If your board is on a different port, edit the `Makefile` or override it: `make upload PORT=/dev/ttyUSB0`.
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
#define P1_BTN_BOTTOM 12
|
||||
#define P2_BTN_UP 11
|
||||
#define P2_BTN_BOTTOM 10
|
||||
#define MATRIX_WIDTH 12
|
||||
#define MATRIX_HEIGHT 8
|
||||
|
||||
// create LED matrix object
|
||||
ArduinoLEDMatrix matrix;
|
||||
|
||||
// initial pong frame
|
||||
byte frame[8][12] = {
|
||||
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 },
|
||||
@@ -28,8 +30,8 @@ int p2_start= 4;
|
||||
int p2_end= 6;
|
||||
|
||||
// initials balls coordinates
|
||||
int ball_reset_x=6;
|
||||
int ball_reset_y=3;
|
||||
int ball_reset_x= MATRIX_WIDTH / 2;
|
||||
int ball_reset_y= MATRIX_HEIGHT / 2;
|
||||
int ball_x= ball_reset_x;
|
||||
int ball_y= ball_reset_y;
|
||||
|
||||
@@ -68,9 +70,8 @@ void render_matrix() {
|
||||
if (!need_refresh) return;
|
||||
need_refresh= 0;
|
||||
// clear
|
||||
for (int x=0; x < 12; x++) {
|
||||
for (int y=0; y < 8; y++) {
|
||||
frame[y][x]= 0;
|
||||
for (int x=0; x < MATRIX_WIDTH; x++) {
|
||||
for (int y=0; y < MATRIX_HEIGHT; y++) {
|
||||
frame[y][x]= 0;
|
||||
}
|
||||
}
|
||||
@@ -80,13 +81,13 @@ void render_matrix() {
|
||||
frame[i][0]= 1;
|
||||
}
|
||||
for (int i= p2_start; i < p2_start+bar_length; i++) {
|
||||
frame[i][11]= 1;
|
||||
frame[i][MATRIX_WIDTH-1]= 1;
|
||||
}
|
||||
|
||||
// ball coords
|
||||
frame[ball_y][ball_x]= 1;
|
||||
|
||||
matrix.renderBitmap(frame, 8, 12);
|
||||
matrix.renderBitmap(frame, MATRIX_HEIGHT, MATRIX_WIDTH);
|
||||
}
|
||||
|
||||
void pong_move_p1() {
|
||||
@@ -136,7 +137,7 @@ void point_scored() {
|
||||
|
||||
void move_ball() {
|
||||
need_refresh= 1;
|
||||
if (ball_x < 0 || ball_x > 11 || ball_y < 0 || ball_y > 7) {
|
||||
if (ball_x < 0 || ball_x > MATRIX_WIDTH-1 || ball_y < 0 || ball_y > MATRIX_HEIGHT-1) {
|
||||
// ball out of matrix limits
|
||||
ball_x= ball_reset_x;
|
||||
ball_y= ball_reset_y;
|
||||
@@ -158,7 +159,7 @@ void move_ball() {
|
||||
if (!ball_player_collision(p1_start)) {
|
||||
// else p2 score, reset board
|
||||
p2_score += 1;
|
||||
Serial.println("Player 2 Point");
|
||||
Serial.println("Player 2 Scores");
|
||||
point_scored();
|
||||
}
|
||||
else {
|
||||
@@ -166,11 +167,11 @@ void move_ball() {
|
||||
ball_move_x= ball_move_x * -1;
|
||||
}
|
||||
}
|
||||
else if (ball_x == 11) {
|
||||
else if (ball_x == MATRIX_WIDTH-1) {
|
||||
if (!ball_player_collision(p2_start)) {
|
||||
// else p1 score, reset board
|
||||
p1_score += 1;
|
||||
Serial.println("Player 1 Point");
|
||||
Serial.println("Player 1 Scores");
|
||||
point_scored();
|
||||
}
|
||||
else {
|
||||
@@ -179,7 +180,7 @@ void move_ball() {
|
||||
}
|
||||
}
|
||||
|
||||
if (ball_y == 0 || ball_y == 7) {
|
||||
if (ball_y == 0 || ball_y == MATRIX_HEIGHT-1) {
|
||||
// reverse y, go down
|
||||
ball_move_y= ball_move_y * -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user