Pages: [1] 2 3 ... 8   Go Down
Author Topic: Arduino Nes controller, Please Help!  (Read 7505 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So i came across this project i wanted to do, but i know nothing about code and im getting a bunch to errors. heres the original link
(i have Leonardo and im using 1.0.3)

http://www.instructables.com/id/USB-NES-controller-with-an-arduino/

And heres the code for the 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);
pinMode(latch, OUTPUT);
        pinMode(clock, OUTPUT);
        pinMode(data, INPUT);
}

void loop() {
  output = 0;
  ReadNESjoy();
  Serial.print(output, BYTE);
}


void ReadNESjoy() {
  latchlow;
  clocklow;
  latchhigh;
  wait;
  latchlow;
  for (int i = 0; i < 8; i++) {
     clockhigh;
     wait;
     output += dataread * (1 << i);
     clocklow;
     wait;
  }
}

It says "BYTE" is no longer used



And heres the code for Processing, idk what it is. (first time using arduino, or any code for that matter and yes i did look around to find any solutions..... none)

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()[1], 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);}}
}

It says "import" is not used or something like that

Here are the files where i got the code from
http://www.instructables.com/files/orig/F2U/W6FP/GVXHOG2Y/F2UW6FPGVXHOG2Y.zip

if you could help me, i would highly appreciate it
thanks to anyone who answers smiley-grin
« Last Edit: January 31, 2013, 11:33:05 pm by Craftee » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So i came across this project i wanted to do, but i know nothing about code and im getting a bunch to errors. heres the original link
(i have Leonardo and im using 1.0.3)

http://www.instructables.com/id/USB-NES-controller-with-an-arduino/

And heres the code for the 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);
pinMode(latch, OUTPUT);
        pinMode(clock, OUTPUT);
        pinMode(data, INPUT);
}

void loop() {
  output = 0;
  ReadNESjoy();
  Serial.print(output, BYTE);
}


void ReadNESjoy() {
  latchlow;
  clocklow;
  latchhigh;
  wait;
  latchlow;
  for (int i = 0; i < 8; i++) {
     clockhigh;
     wait;
     output += dataread * (1 << i);
     clocklow;
     wait;
  }
}

It says "BYTE" is no longer used



And heres the code for Processing, idk what it is. (first time using arduino, or any code for that matter and yes i did look around to find any solutions..... none)

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()[1], 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);}}
}

it says   'import' does not name a type

Here are the files where i got the code from
http://www.instructables.com/files/orig/F2U/W6FP/GVXHOG2Y/F2UW6FPGVXHOG2Y.zip

if you could help me, i would highly appreciate it
thanks to anyone who answers smiley-grin
« Last Edit: January 31, 2013, 11:53:41 pm by Craftee » Logged

Johannesburg. UTC+2
Offline Offline
Faraday Member
**
Karma: 106
Posts: 4692
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
not used or something like that

You're not going to get many responses to a question something like that
Logged

The Elders of the Internet know who I am
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
not used or something like that

You're not going to get many responses to a question something like that

It says exactly

Code:
'import' does not name a type
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 640
Posts: 50335
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you trying to compile the Processing sketch in the Arduino IDE? That's exactly the error I get when I try that.

A visit to http://processing.org is in your future.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 502
Posts: 19085
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

- Moderator
Logged


Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

- Moderator


D: sorry, i wasnt getting any responses so i expanded my search smiley-sad forgive me


also, how do i fix the "BYTE" problem?(i have no clue as to what im doing)
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you trying to compile the Processing sketch in the Arduino IDE? That's exactly the error I get when I try that.

A visit to http://processing.org is in your future.

I downloaded it and rand the thing through processing, but now i get
Code:
cannot find anything named "KeyEvent.VK_L"
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so i have this old peice of code here, and i get an error saying "The 'BYTE' keyword is no longer supported" so what do i use instead? please help!

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);
pinMode(latch, OUTPUT);
        pinMode(clock, OUTPUT);
        pinMode(data, INPUT);
}

void loop() {
  output = 0;
  ReadNESjoy();
  Serial.print(output, BYTE);
}


void ReadNESjoy() {
  latchlow;
  clocklow;
  latchhigh;
  wait;
  latchlow;
  for (int i = 0; i < 8; i++) {
     clockhigh;
     wait;
     output += dataread * (1 << i);
     clocklow;
     wait;
  }
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26496
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Topics merged.
Please don't start a new thread on the same subject.

Look up "Serial.write".
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Topics merged.
Please don't start a new thread on the same subject.

Look up "Serial.write".

i did look it up, telling me "look up serial.write" doesnt tell me anything. i think as a moderator you could help? jeeze
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

and i get an answer already? so i can move on with my life? seriously why do i have to wait so long for a legit response?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26496
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Four minutes to a bump post?

Quote
"look up serial.write" doesnt tell me anything.
How am I supposed to know that?

Quote
i think as a moderator you could help?
I saved you the embarrassment of having your cross-posting reported as a violation of forum rules, didn't I?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Four minutes to a bump post?

Quote
"look up serial.write" doesnt tell me anything.
How am I supposed to know that?

Quote
i think as a moderator you could help?
I saved you the embarrassment of having your cross-posting reported as a violation of forum rules, didn't I?

... talk about policing, is this where i come to get help? or is it a place for forum moderators to do their job?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26496
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm a janitor, not a policeman.

I clean up after untidy posters.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1] 2 3 ... 8   Go Up
Jump to: