
Code #include <Tone.h>
Tone noiseMaker;
int bobb = 0; //variable that declares
int score2 =0; // sets score as 0 n stuff
int score1 = 0; // sets score as 0 n stuff
int player2=0; // player 2 score n stuff
int player1=0; // player 1 score n stuff
int pace = 1000; // sets pace of ball n stuff
int time=0; // sets delay to 0 n stuff
int y = 0; // sets initial y value to 0 n stuff
int x=0; // sets initial x value to 0 n stuff
int xD=1; //sets x direction of ball
int yD=1; //sets y direction of ball
int minus[]={3,4,2,4,2,3,6,7,5,7,5,6,9,10,8,10,8,9,12,13,11,13,11,12,14,15,16,15,16,14}; // declares negatives of pins n stuff
int plus[]={4,3,4,2,3,2,7,6,7,5,6,5,10,9,10,8,9,8,13,12,13,11,12,11,15,14,15,16,14,16}; // declares positives of pins n stuff
int led; // declares LED n stuff
int val =0; // sets inital value to 0 n stuff
int val1=0; //sets inital value to 0 n stuff
int paddleminus1[]= {3,4,2,4,2,3}; //
int paddleplus1 []= {4,3,4,2,3,2}; //
int paddleminus2[]= {14,15,16,15,16,14}; //
int paddleplus2[] = {15,14,15,16,14,16}; //
int woot [5][6]= // declares n stuff
{
{0,1,2,3,4,5},
{6,7,8,9,10,11},
{12,13,14,15,16,17},
{18,19,20,21,22,23},
{24,25,26,27,28,29},
}; // Declares pins in arrays n stuff
void setup() // This is the setup n stuff
{
noiseMaker.begin(17); // makes noise n stuff
for (int pin=1; pin<18;pin++) // makes noise at a certain pin n stuff
{
pinMode(pin,INPUT); // sets pin as input n stuff
}
Serial.begin(9600); // makes it start n stuff
}
void loop() // this is the loop n stuff
{
led=woot[y][x]; //
for(time=0;time <= pace;time++) //
{
val = analogRead(4); //reads the potentiameter input
val1 = analogRead(5); //reads the potentiameter input
val = map(val,0,1023,0,5); //resets the values of the potentiameter to correspond to the lights
val1 = map(val1,0,1023,0,5); //resets the values of the potentiameter to correspond to the lights
pinMode(paddleplus1[val],OUTPUT); //sets the positive paddles as an output
pinMode(paddleminus1[val],OUTPUT); //sets the negative paddles as an output
digitalWrite(paddleplus1[val],HIGH); //sends which light to light up
digitalWrite(paddleminus1[val],LOW); //sends which light to light up
pinMode(paddleplus1[val],INPUT); //sets the paddles back to inputs
pinMode(paddleminus1[val],INPUT); //sets the paddles back to inputs
pinMode(paddleplus2[val1],OUTPUT); //same as paddle one
pinMode(paddleminus2[val1],OUTPUT); //same as paddle one
digitalWrite(paddleplus2[val1],HIGH); //same as paddle one
digitalWrite(paddleminus2[val1],LOW); //same as paddle one
pinMode(paddleplus2[val1],INPUT); //same as paddle one
pinMode(paddleminus2[val1],INPUT); //same as paddle one
pinMode(plus[led],OUTPUT); //sets the positive ball as an output
pinMode(minus[led],OUTPUT); //sets the negative ball as an output
digitalWrite(plus[led],HIGH); //sends which light to light up as the ball
digitalWrite(minus[led],LOW); //sends which light to light up as the ball
pinMode(plus[led],INPUT); //sets the ball back to input
pinMode(minus[led],INPUT); //sets the ball back to input
}
y=y+yD; // sets y = to y plus yD n stuff
x=x+xD; // sets x = to x plus xD n stuff
if(x>5) // if x value is greater than 5 n stuff
{xD=xD*(-1); // multiplies the x
x=4;
noiseMaker.play(400);
delay(50);
noiseMaker.stop();
// Sets X value to 4
}
if (x<0) //
{xD=xD*(-1); //
x=1;
noiseMaker.play(400);
delay(50);
noiseMaker.stop();
// Sets X value to 1
}
//left side
if (y == 0)
{
if(x==val || x==val+1)
{
yD=yD*(-1);
y=1;
pace=pace*.9;
noiseMaker.play(400);
delay(50);
noiseMaker.stop();
}
else
{delay(1000);
x=val1;
yD=yD*(-1);
y= 4;
pace=1000;
player2= player2+1;
for (int bobb=0; bobb<6000;bobb++)
for(int score2=0; score2<(player2);score2++)
{
pinMode(paddleplus2[score2],OUTPUT);
pinMode(paddleminus2[score2],OUTPUT);
digitalWrite(paddleplus2[score2],HIGH);
digitalWrite(paddleminus2[score2],LOW);
pinMode(paddleplus2[score2],INPUT);
pinMode(paddleminus2[score2],INPUT);
delayMicroseconds(10);
if (score2==6)
{
for (int x=0; x<6; x++)
{
led=woot[y][x];
pinMode(plus[led],OUTPUT);
pinMode(minus[led],OUTPUT);
digitalWrite(plus[led],HIGH);
digitalWrite(minus[led],LOW);
delay(500);
Serial.println(led);
pinMode(plus[led],INPUT);
pinMode(minus[led],INPUT);
}
}
}
}
}
//right side
if (y == 4)
{
if(x==val1 || x==val1+1)
{
yD=yD*(-1);
y=3;
pace=pace*.9;
noiseMaker.play(400);
delay(50);
noiseMaker.stop();
}
else
{delay(1000);
x=val;
y=0;
pace=1000;
player1= player1+1;
for (int bob=0; bob<6000;bob++)
for(int score1=0; score1<(player1);score1++)
{
pinMode(paddleplus1[score1],OUTPUT);
pinMode(paddleminus1[score1],OUTPUT);
digitalWrite(paddleplus1[score1],HIGH);
digitalWrite(paddleminus1[score1],LOW);
pinMode(paddleplus1[score1],INPUT);
pinMode(paddleminus1[score1],INPUT);
delayMicroseconds(10);
if (score1==6)
{
for (int x=0; x<6; x++)
{
led=woot[y][x];
pinMode(plus[led],OUTPUT);
pinMode(minus[led],OUTPUT);
digitalWrite(plus[led],HIGH);
digitalWrite(minus[led],LOW);
delay(500);
Serial.println(led);
pinMode(plus[led],INPUT);
pinMode(minus[led],INPUT);
}
}
}
}
}
}
Problems Encountered
Make noise when the ball hits the side.
Play music for the winning side.
Instead of using one-light paddles on either side, we changed the
values so that the paddles light up two LEDs at one time n stuff. We
also had to change the analog values so that instead of it using pins
0-5, it now uses 0-4 because we used val+1, making it light up the
original pin and the next one in succession, and you can't light up
pins 5 and 6 when there is no pin 6 n stuff.