Current Code:
int UP = 0;
int DOWN = 1;
int LEFT = 2;
int RIGHT = 3;
int AB = 4;
int STARTC = 5;
char controller_data[8];
/* SETUP */
void setup()
{
Serial.begin(115200);
pinMode(UP,OUTPUT);
pinMode(DOWN,OUTPUT);
pinMode(datin,INPUT);
}
/* CONTROLLER READ */
void controllerRead()
{
digitalWrite(UP, LOW);
digitalWrite(DOWN,LOW);
digitalWrite(LEFT,LOW);
digitalWrite(RIGHT,LOW);
digitalWrite(AB,LOW);
digitalWrite(STARTC,LOW);
delayMicroseconds(200);
digitalWrite(UP,LOW);
if (digitalRead(datin) == 1)
{
controller_data[0] = 'x';
}
else
{
controller_data[0] = 'o';*/
}
{
digitalWrite(UP,HIGH);
delayMicroseconds(200);
if (digitalRead(datin) == 1)
{
controller_data[i] = 'x';
}
else
{
controller_data[i] = 'o';
}
digitalWrite(DOWN,LOW);
delayMicroseconds(200);
}
}*/
/* PROGRAM */
void loop()
{
controllerRead();
for (int i = 0; i <= 7; i++){
Serial.print(controller_data[i]);
delayMicroseconds(200);
}
Serial.println('z');
delay(10);
}
import processing.serial.;
println(Serial.list());
Serial GENjoy;
String buttons;
Robot VKey;
PImage bg;
void setup()
{
size(434,180);
frameRate(30);
String portName = Serial.list()[4];
GENjoy = new Serial(this, portName, 115200);
try
{
VKey = new Robot();
}
catch(AWTException a){}
GENjoy.buffer(11);
buttons = "...";
// The image NES-Controller.jpg has to be in the same map as the .pde / binary
bg = loadImage("NES-Controller.jpg");
}
void draw()
{
background(bg);
fill(255, 255, 0);
// Check all keys
for (int i = 0; i <= 7; i++)
{
// Is button pressed?
if (buttons.charAt(i) == 'o')
{
// Press the appropiate key
switch(i)
{
case 0:
VKey.keyPress(KeyEvent.VK_A);
ellipse(363,127,40,40); // A
break;
case 1:
VKey.keyPress(KeyEvent.VK_B);
ellipse(307,127,40,40); // B
break;
case 2:
VKey.keyPress(KeyEvent.VK_E);
rect(155, 121, 37, 15); // Select
break;
case 3:
VKey.keyPress(KeyEvent.VK_T);
rect(211, 121, 37, 15); // Start
break;
case 4:
VKey.keyPress(KeyEvent.VK_U);
rect(61, 68, 28, 24); // Up
break;
case 5:
VKey.keyPress(KeyEvent.VK_D);
rect(61, 122, 28, 24); // Down
break;
case 6:
VKey.keyPress(KeyEvent.VK_L);
rect(36, 93, 24, 28); // Left
break;
case 7:
VKey.keyPress(KeyEvent.VK_R);
rect(90, 93, 24, 28); // Right
break;
}}
// Is the button released?
if (buttons.charAt(i) == 'x')
{
// Release the appropiate key
switch(i)
{
case 0:
VKey.keyRelease(KeyEvent.VK_A);
break;
case 1:
VKey.keyRelease(KeyEvent.VK_B);
break;
case 2:
VKey.keyRelease(KeyEvent.VK_E);
break;
case 3:
VKey.keyRelease(KeyEvent.VK_T);
break;
case 4:
VKey.keyRelease(KeyEvent.VK_U);
break;
case 5:
VKey.keyRelease(KeyEvent.VK_D);
break;
case 6:
VKey.keyRelease(KeyEvent.VK_L);
break;
case 7:
VKey.keyRelease(KeyEvent.VK_R);
break;
}}}
}
// This event gets activated as soon as the buffer is full
serialEvent(Serial GENjoy)
{
// Read the buffer into a string
buttons = GENjoy.readString();
}
The code is edited from the code posted by the user Prodigity on Instructables.
As you may guess I am currently focusing on just getting the Genesis controller to work on the PC before I worry about tackling the motion controls aspect.Any advice on how to fix the code so that it works for what I need would be appreciated.