Arduino Pong With Dot Matrix

Yes
And when the ball hits a wall you have to switch x_dir or y_dir from 1 to -1 or the other way round, but only x_dir or y_dir, not both.

@er_name_not_found I have sort-of figured out how to go backwards from the wall, it just won't move the ball after that:


#include "LedControl.h"
const byte DIN = 10;
const byte CS = 11;
const byte CLK = 12;

int x;
int y;

int x_dir = 1;
int y_dir = 1;

LedControl screen = LedControl(DIN, CLK, CS, 1);
byte board[8] = {B00000000 , B00000000 , B00000000 , B00000000 , B00000000 , B00000000 , B00000000, B00000000};
byte row;

// Update display to reflect board
void print_board() {
  for (row = 0; row < 8; row++) {
    screen.setRow(0, row, board[row]);
  }
}

// value = 1 turn on led
// value = 0 turn off led
// choose row and column
void set_led(byte row, byte column, byte value) {
  if (value == 0) {
    board[row] = bitClear(board[row], column);
  } else {
    board[row] = bitSet(board[row], column);
  }
}

void setup() {
  screen.shutdown(0, false);
  screen.setIntensity(0, 8);
  screen.clearDisplay(0);
}

void loop() {

  set_led(y, x, 0);

  x += x_dir;

  set_led(y, x, 1);

  if (x == 7) {
    x -= x_dir;
    set_led(y, x, 0);
    print_board();
    set_led(y, x, 1);
    delay(250);
  }

  print_board();

  delay(250);

}

Too complex
x += x_dir should always work. It's the value of x_dir that changes from +1 to -1.

@er_name_not_found I've got it now:


#include "LedControl.h"
const byte DIN = 10;
const byte CS = 11;
const byte CLK = 12;

int x;
int y;

int x_dir = 1;
int y_dir = 1;

LedControl screen = LedControl(DIN, CLK, CS, 1);
byte board[8] = {B00000000 , B00000000 , B00000000 , B00000000 , B00000000 , B00000000 , B00000000, B00000000};
byte row;

// Update display to reflect board
void print_board() {
  for (row = 0; row < 8; row++) {
    screen.setRow(0, row, board[row]);
  }
}

// value = 1 turn on led
// value = 0 turn off led
// choose row and column
void set_led(byte row, byte column, byte value) {
  if (value == 0) {
    board[row] = bitClear(board[row], column);
  } else {
    board[row] = bitSet(board[row], column);
  }
}

void setup() {
  screen.shutdown(0, false);
  screen.setIntensity(0, 8);
  screen.clearDisplay(0);
}

void loop() {

  set_led(y, x, 0);

  x += x_dir;

  set_led(y, x, 1);

  if (x == 7) {
    x_dir--;
    set_led(y, x, 0);
    print_board();
    set_led(y, x, 1);
    delay(250);
  }

  if (x == 0) {
    x_dir++;
    set_led(y, x, 0);
    print_board();
    set_led(y, x, 1);
    delay(250);
  }

  print_board();

  delay(250);

}

@er_name_not_found Why does it "skip" one occasionally?

LDM Test Blink

@er_name_not_found How do I implement this with the paddles? Like, how do I get the Arduino to recognize whether or not the ball has hit the paddle?

You know where the paddles are by the column they are in an the position of the encoder. You have to compare those to the ball position before you move the ball.

@er_name_not_found Is it x_dir or x? Do I use a comparison symbol? I am unsure what you mean by "compare those."

Sorry. You need to learn a bit more about programming in general. I have explained every step in sufficient detail.
The last thing I want to do is to discourage you, but I can't explain it anymore without taking you through the basics of programming or writing the program for you. I hope you understand this is to encourage you to learn and not a judgement in any way.
My recommendation is that you start learning C++ basics before continuing with a project as complex as this.
You will need to understand how to objectify concepts like the led matrix, ball, and paddles, and how to represent those objects using variables. Text based games like guess a number, tic-tac-toe, and Yahtzee are great projects that will help you to develop this manner of thinking.
I suggest shelfing this project for now. After you put in work on the basics and have made some text based games on your own then you can return to this and try again. These notes will be here when you return and so will I.

@er_name_not_found Understandable. Thank you for all your help (I'll link this in the code)! I will try to learn more about programming with those projects.

Excellent.
I'm happy to help when you're ready, but I suspect that after you've learned a bit more that you will be able to review this thread and create your pong game much more easily.