Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Obaid2902
Created March 31, 2016 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Obaid2902/524ed8ea16b7660349abbee7bdad9d8d to your computer and use it in GitHub Desktop.
Save Obaid2902/524ed8ea16b7660349abbee7bdad9d8d to your computer and use it in GitHub Desktop.
// Libraries
import processing.serial.*;
import cc.arduino.*;
//Calling Arduino Ports
//Numbers represent pins
Arduino arduino;
int RightPin1 = 2;
int DownPin1 = 3;
int LeftPin1 = 4;
int UpPin1 = 5;
int RightPin2 = 6;
int DownPin2 = 7;
int LeftPin2 = 8;
int UpPin2 = 9;
// Proceesing ints and floats
int directionX1 = 2, directionY1 = 0, directionX2 = -2, directionY2 = 0;
float x1=500, y1=500, x2=1420, y2=500, speed=3.5;
void setup()
{
size(1920, 1080);
background(0);
smooth();
noStroke();
// Calling on arduino and listenting for the pins
arduino = new Arduino(this, "COM6", 9600); // Will have to change for MAC users
arduino.pinMode(RightPin1, Arduino.INPUT);
arduino.pinMode(DownPin1, Arduino.INPUT);
arduino.pinMode(LeftPin1, Arduino.INPUT);
arduino.pinMode(UpPin1, Arduino.INPUT);
arduino.pinMode(RightPin2, Arduino.INPUT);
arduino.pinMode(DownPin2, Arduino.INPUT);
arduino.pinMode(LeftPin2, Arduino.INPUT);
arduino.pinMode(UpPin2, Arduino.INPUT);
}
void draw() {
//giving the elipeses momentum
x1 = x1+speed*directionX1;
y1 = y1+speed*directionY1;
x2 = x2+speed*directionX2;
y2 = y2+speed*directionY2;
//Checking boundries
if ((x1>width) || (x1<0))
{
directionX1=-directionX1;
}
if ((y1>height) || (y1<0))
{
directionY1=-directionY1;
}
if ((x2>width) || (x2<0))
{
directionX2=-directionX2;
}
if ((y2>height) || (y2<0))
{
directionY2=-directionY2;
}
// Our player 1 Player 2 ellipses
fill(0, 255, 0);
ellipse(x1, y1, 100, 75);
fill(255, 0, 0);
ellipse(x2, y2, 100, 75);
//Controls for player 1 and player 2
if (arduino.digitalRead(4) == Arduino.HIGH)
{
directionX1=-1;
directionY1=0;
} else if (arduino.digitalRead(2) == Arduino.HIGH) {
directionX1=1;
directionY1=0;
} else if (arduino.digitalRead(5) == Arduino.HIGH) {
directionY1=-1;
directionX1=0;
} else if (arduino.digitalRead(3) == Arduino.HIGH) {
directionY1=1;
directionX1=0;
} else if (arduino.digitalRead(8) == Arduino.HIGH) {
directionX1=-1;
directionY1=0;
} else if (arduino.digitalRead(6) == Arduino.HIGH) {
directionX1=1;
directionY1=0;
} else if (arduino.digitalRead(9) == Arduino.HIGH) {
directionY1=-1;
directionX1=0;
} else if (arduino.digitalRead(3) == Arduino.HIGH) {
directionY1=1;
directionX1=0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment