Things used in this project

Hardware components:
Ard nano
Arduino Arduino Nano R3
×2
13944 01
SparkFun SparkFun 9DoF Sensor Stick
×1
11026 02
Jumper wires (generic)
×1
Neopixel strip
NeoPixel strip
×1
HC-05
×1
Tens70
9V battery (generic)
×1
Software apps and online services:
Ide web
Arduino Arduino IDE
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)

Schematics

Controller Schematic
Controller scematic bb cyf7rhpzmp
Matrix Schematic
Thumbnail bb 4tjx0di86l

Code

Matrix CodeC/C++
Goes on the Arduino attached to the matrix.
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <EEPROM.h>

#define PIN 6 //Data pin for matrix
#define EEPROM_ADR 0x50 //The I2C address of the EEPROM
#define HS_ADR 0x02 //The address of the highscore byte in the EEPROM

#define NOTE_C1  33
#define SPKR_PIN 3

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(15, 10, PIN,
  NEO_MATRIX_BOTTOM     + NEO_MATRIX_LEFT +
  NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
  NEO_GRB            + NEO_KHZ800);
  
int ball_x = 7; //Ball's X coord
int ball_y = 2; //Ball's Y coord
int radius = 1; //Ball's radius
int r_incr = 1; //How much to increase radius by
bool isSwung = false; //Is the raquet swung
int ball_x_dir = 1; //Ball's X direction
int ball_y_dir = 1; //Ball's Y direction
bool isDirRight = true;
int score = 0; //The score of the current game
int COM_score = 0;
int highscore = 0; //The high score of all games
int framerate = 50; //How many ms between each frame
int serial_data;
String score_string = "";
uint16_t colors[] = {matrix.Color(255,0,0),matrix.Color(0,255,0),matrix.Color(150,200,0)};
int melody[] = {0};
int tempo[] = {0};
static unsigned long lastFrame = 0;

void setup(){
  Serial.begin(9600);
  matrix.begin();
  matrix.fillScreen(0);
  matrix.setTextColor(colors[1]);
  randomSeed(analogRead(A2));
  display_scores();
  highscore = read_HS();
  Serial.println(highscore,DEC);
  matrix.setCursor(0,1);
  matrix.print("HS: ");
  matrix.show();
  delay(1000);
  matrix.fillScreen(0);
  matrix.setCursor(0,1);
  matrix.print(highscore,DEC);
  matrix.show();
  delay(1000);
  score_string = "";
}

void loop(){
  if((lastFrame+framerate)< millis()){
    update_frame();
    lastFrame = millis();
  }
}

void update_frame(){
  serial_data = Serial.parseInt();
  if(serial_data){
    isSwung = true;
  }
  else if(!serial_data){
    isSwung = false;
  }
  if(ball_y >= 5 && ball_y < 7 && isSwung){
    if(isDirRight){
    ball_x_dir = -1;
    ball_y_dir = -1;
    }
    else if(!isDirRight){
      ball_x_dir = 1;
      ball_y_dir = -1;
    }
    r_incr = -1;
  }
  else if(ball_y >= 8){
    COM_score += 1;
    end_round();
    
  }
  else if(ball_y <= 2){
    isDirRight = !isDirRight;
    int randNum = random(4);
    Serial.println(randNum);
    if(randNum == 2){ //25% chance of COM missing
      score += 1;
      if(score > highscore){
      write_HS();
  }
      end_round;
    }
    else{
      if(isDirRight){
      ball_x_dir = 1;
      ball_y_dir = 1;
      }
      else if(!isDirRight){
        ball_x_dir = -1;
        ball_y_dir = 1;
      }
      r_incr = 1;
    }
  }
  ball_x += ball_x_dir;
  ball_y += ball_y_dir;
  radius += r_incr;
  matrix.fillScreen(0);
  matrix.fillCircle(ball_x,ball_y,radius,colors[2]);
  matrix.show();
}

void end_round(){
  
  if(COM_score >= 10){
    end_game();
  }
  isDirRight = true;
  r_incr = 1;
  ball_x_dir = 1;
  ball_y_dir = 1;
  ball_x = 7;
  ball_y = 2;
  radius = 1;
  display_scores();
  matrix.fillScreen(0);
  matrix.fillCircle(ball_x,ball_y,radius,colors[2]);
  matrix.show();
  
}

void end_game(){
  matrix.fillScreen(0);
  matrix.setCursor(0,1);
  matrix.setTextColor(colors[0]);
    matrix.drawLine(3,0,12,9,colors[0]);
    matrix.drawLine(11,0,2,9,colors[0]);
    matrix.show();
    delay(500);
  while(1){
  }
}

void display_scores(){
  matrix.fillScreen(0);
  matrix.setTextColor(colors[1]);
  matrix.setCursor(0,1);
  score_string = String(score) + "-" + String(COM_score);
  scrollText(score_string);
  matrix.fillScreen(0);
  delay(2000);
  matrix.show();
}

void scrollText(String text){
  int pass = 0;
  int x = matrix.width();
  for(int i=0;i<24;i++){
  matrix.fillScreen(0);
  matrix.setCursor(x,2);
  matrix.print(text);
  x -= 1;
  matrix.show();
  delay(150);
  }
}

void write_HS(){
  EEPROM.write(0x04,int(score));
}

int read_HS(){
  byte HS = EEPROM.read(0x04); //Read from address 4
  return HS;
}
Racquet CodeC/C++
#include <Wire.h>
#include <SPI.h>
#include <SparkFunLSM9DS1.h>

LSM9DS1 imu;

#define LSM9DS1_M  0x1E // Would be 0x1C if SDO_M is LOW
#define LSM9DS1_AG  0x6B // Would be 0x6A if SDO_AG is LOW

#define PRINT_SPEED 10 // 10 ms between checks
static unsigned long lastPrint = 0; // Keep track of print time

float accelx = 0;
float accely = 0;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
imu.settings.device.commInterface = IMU_MODE_I2C;
  imu.settings.device.mAddress = LSM9DS1_M;
  imu.settings.device.agAddress = LSM9DS1_AG;
  if (!imu.begin())
  {
   //failed
    while (1)
      ;
  }
}

void loop() {
   if ((lastPrint + PRINT_SPEED) < millis())
  {
  // put your main code here, to run repeatedly:
  if ( imu.accelAvailable() )
  {
    // To read from the accelerometer, first call the
    // readAccel() function. When it exits, it'll update the
    // ax, ay, and az variables with the most current data.
    imu.readAccel();
  }
  lastPrint = millis(); // Update lastPrint time
  }
  accelx = imu.calcAccel(imu.ax);
  accely = imu.calcAccel(imu.ay);

  if(accelx <= -1.5 || accelx >= 1.5){
    Serial.print(1);
    delay(600);
  }
  else if(accely <= -1.5 || accely >= 1.5){
    Serial.print(1);
    delay(600);
}
}
Python CodePython
import serial
import time

matrix_port = "COM3"
raquet_port = "COM9"

matrix = serial.Serial(matrix_port, 9600)
racquet = serial.Serial(raquet_port,9600)
time.sleep(10)
while 1:
    data = racquet.read()
    print data
    if data == "1":
        print "hit"
        matrix.write("1")
        time.sleep(1)
    time.sleep(.05)

Credits

Download
Arduino “having11” Guy

I love creating cloud solutions that can interact with hardware along with using Arduino boards and Raspberry Pis to create new projects.

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

IoT Based Garden Automation And Monitoring System
Advanced
  • 354
  • 10

Full instructions

Automate Your Garden with Arduino and Cayenne

URB (Universal Railway Model Bus)  - Automate Your Layout
Advanced
  • 103
  • 3

Work in progress

All features Arduino, plus: direct plug servos, motor drivers, high-current outputs, built-in I2C bus, convenient connections, and more.

Hank the HexaPod - Mega Bread Robotics Series # 7
Advanced
  • 168
  • 4

Work in progress

After a few months of gathering parts, reading about the new hardware, and ripping my hair out due to no support. I done did it Paw.

Punch Activated Arm Flamethrowers (Real Firebending)
Advanced
  • 42,866
  • 328

Shoot fireballs from your fists when you throw a punch with these arm mounted smart flamethrowers!

Visual Capturing with OV7670 on Arduino
Advanced
  • 4,737
  • 24

Protip

This is an Arduino camera module, using the surveillance camera's digital image processing chip-OV0706.

Get Nostalgic and Use Nokia 84x48 LCD with Arduino
Advanced
  • 3,131
  • 14

Protip

These 84 by 48 pixel LCDs are what you might have found in Nokia 3310. And what about using them in the Arduino projects?

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog