Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
craftee
craftee's Profile
1
Posts
0
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
Nes controller processing problems
[0 Replies]
01-Feb-2013 01:53 PM
Forum:
Integration and Hardware
so i have this arduino code, it works fine, but i think theres something wrong with my processing code, help is appreciated!
arduino code
const int latch = 2;
const int clock = 3;
const int data = 4;
#define latchlow digitalWrite(latch, LOW)
#define latchhigh digitalWrite(latch, HIGH)
#define clocklow digitalWrite(clock, LOW)
#define clockhigh digitalWrite(clock, HIGH)
#define dataread digitalRead(data)
#define wait delayMicroseconds(200)
byte output;
void setup()
{
Serial.begin(9600);
while (! Serial ) { }
pinMode(latch, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(data, INPUT);
}
void loop()
{
output = 0;
ReadNESjoy();
// Serial.write(output);
Serial.println ((unsigned int)output);
}
void ReadNESjoy()
{
latchlow;
clocklow;
latchhigh;
wait;
latchlow;
for (int i = 0; i < 8; i++) {
clockhigh;
wait;
output += dataread * (1 << i);
clocklow;
wait;
}
}
heres the processing code
import processing.serial.*;
import java.awt.*;
Serial arduino;
Robot VKey;
PImage bgImage;
char recvout;
char prevout;
char deltaout;
void setup() {
size(434,180);
frameRate(30);
println(Serial.list());
arduino = new Serial(this, Serial.list()[0], 9600); // ATTENTION!!!
bgImage = loadImage("NEScontroller.jpg");
try
{
VKey = new Robot();
}
catch(AWTException a){}
prevout = 0;
}
void draw() {
if (bgImage != null) { background(bgImage); }
fill(255, 255, 0);
serialRead();
deltaout = (char)((int)recvout ^ (int)prevout);
emulateKeyboard();
prevout = recvout;
}
void serialRead() {
while (arduino.available() > 0) {
recvout = arduino.readChar();
}
}
void emulateKeyboard() {
if ((deltaout & 1 ) == 1 ) { if ((recvout & 1 ) == 1 ) {VKey.keyPress(KeyEvent.VK_L);} else {VKey.keyRelease(KeyEvent.VK_L);}}
if ((deltaout & 2 ) == 2 ) { if ((recvout & 2 ) == 2 ) {VKey.keyPress(KeyEvent.VK_K);} else {VKey.keyRelease(KeyEvent.VK_K);}}
if ((deltaout & 4 ) == 4 ) { if ((recvout & 4 ) == 4 ) {VKey.keyPress(KeyEvent.VK_G);} else {VKey.keyRelease(KeyEvent.VK_G);}}
if ((deltaout & 8 ) == 8 ) { if ((recvout & 8 ) == 8 ) {VKey.keyPress(KeyEvent.VK_H);} else {VKey.keyRelease(KeyEvent.VK_H);}}
if ((deltaout & 16 ) == 16 ) { if ((recvout & 16 ) == 16 ) {VKey.keyPress(KeyEvent.VK_W);} else {VKey.keyRelease(KeyEvent.VK_W);}}
if ((deltaout & 32 ) == 32 ) { if ((recvout & 32 ) == 32 ) {VKey.keyPress(KeyEvent.VK_S);} else {VKey.keyRelease(KeyEvent.VK_S);}}
if ((deltaout & 64 ) == 64 ) { if ((recvout & 64 ) == 64 ) {VKey.keyPress(KeyEvent.VK_A);} else {VKey.keyRelease(KeyEvent.VK_A);}}
if ((deltaout & 128) == 128) { if ((recvout & 128) == 128) {VKey.keyPress(KeyEvent.VK_D);} else {VKey.keyRelease(KeyEvent.VK_D);}}
}
im running on 1.5.1
«Prev
Next »
Moderate user : craftee
Forum