Pages: 1 ... 3 4 [5] 6 7 8   Go Down
Author Topic: Arduino Nes controller, Please Help!  (Read 6760 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

i feel stupid, i accidently switched the yellow and brown, its working now ...

OK. What's working? Are you getting numbers in the serial monitor? What number do you see if you press button "a"?



yea i get numbers, when i press "a" the number doesnt change, its just 127.
and i just need help converting the numbers into key emulations
Logged

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

im just a kid that needs help, gosh!

If you think you are capable of solving this problem already with a little help, then you ought to be at least part way there on your own. Show us where you've got so far and which part you need help with, and no doubt there will be plenty of people willing to steer you round the problem.

If you simply don't know where to start, then put this project down and start with something simpler. It's best not to try to boil the ocean - learn things one step at a time.



well i wanna do a project that matters to me, not just some flop project i wont learn anything from, because more often than not, i find myself copying code. i know very little about code.
Logged

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

Well, try something and post what you tried.

What have you tried?

Logged


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

Well, try something and post what you tried.

What have you tried?



:/

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);
        Keyboard.begin();
}

void loop()
{
  if(KeyboardSerial == 127)
  Keyboard.press(a)
    else ()
    Keyboard.release()
  if(KeyboardSerial == 126)
  Keyboard.press(b)
    else ()
    Keyboard.release()
  if(KeyboardSerial == 119)
  Keyboard.press(up_arrow)
    else ()
    Keyboard.release()
  if(KeyboardSerial == 111)
  Keyboard.press(down_arrow)
    else ()
    Keyboard.release()
  if(KeyboardSerial == 63)
  Keyboard.press(right_arrow)
    else ()
    Keyboard.release()
  if(KeyboardSerial == 95)
  Keyboard.press(left_arrow)
    else ()
    Keyboard.release()
  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;
  }
}
Logged

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

You have to start thinking about what you are doing.

Code:
void loop()
{
  if(KeyboardSerial == 127)
 ...

What is KeyboardSerial?

Previously you were displaying the value of output. So surely you want to test that?

Code:
void loop()
{
  if(output == 127)
 ...

But, wait! You are testing it before you find out what it is.

How about:

Code:
void loop()
{
  output = 0;
  ReadNESjoy();

  if(output == 127)
 ...

It's not magic. Think about what the variables mean and use them in a useful way.
Logged


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

Code:
void loop()
{
  output = 0;
  ReadNESjoy();
  Serial.println ((unsigned int)output);
 
  if(output == 127)
  Keyboard.press('a')
    else ()
    Keyboard.release()
  if(output == 126)
  Keyboard.press('b')
    else ()
    Keyboard.release()
  if(output == 119)
  Keyboard.press('up_arrow')
    else ()
    Keyboard.release()
  if(output == 111)
  Keyboard.press('down_arrow')
    else ()
    Keyboard.release()
  if(output == 63)
  Keyboard.press('right_arrow')
    else ()
    Keyboard.release()
  if(output == 95)
  Keyboard.press('left_arrow')
    else ()
    Keyboard.release()
  if(output == 123)
  Keyboard.press('s')
    else ()
    Keyboard.release()
  if(output == 125)
  Keyboard.press('l')
    else ()
    Keyboard.release()

}
Logged

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

it says ";" is expected before else, im not sure where to put it....
Logged

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

Find a book on programming in C. Read it.

Quote
well i wanna do a project that matters to me, not just some flop project i wont learn anything from

You wanna learn? Start reading.
Logged


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

Find a book on programming in C. Read it.

Quote
well i wanna do a project that matters to me, not just some flop project i wont learn anything from

You wanna learn? Start reading.

i did, i even bought a huge book!. but im just not getting it. i figure since alot of people learn by just diving into it, i would try the same
Logged

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

it says ";" is expected before else, im not sure where to put it....

Code:
  if(output == 127)
  Keyboard.press('a');
    else ()
    Keyboard.release()

i fixed the ";" problem, but it says
"expected primary expression before ")"

Code:
    else ()
Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if ( output == 127 )
{
    Keyboard.press('a');
}
else
{
    Keyboard.release();
}
Logged

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

Code:
if ( output == 127 )
{
    Keyboard.press('a');
}
else
{
    Keyboard.release();
}


hmm i tried that, and i got this error "no matching function for call to "Keyboard_::release()
Logged

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

okay i fixed that error with

Code:
if ( output == 127 )
{
    Keyboard.press('a');
}
else
{
    Keyboard.release('a');
}
but now, it spams the "a" button. because for some reason when i serial monitor it, it spams 127 and not 0, im not sure why this is happening
Logged

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 91
Posts: 4226
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
well i wanna do a project that matters to me, not just some flop project i wont learn anything from,

Fair point...

But:

Quote
because more often than not, i find myself copying code. i know very little about code.

I thought you did copy the code, and I'd actually question what you're learning by getting the forum to debug it line by line.

Quote
i figure since alot of people learn by just diving into it, i would try the same

An admirable approach except it's a way of drowning if you don't have a strong support group (read as: forum members patient enough to help while putting up with your impatience as in bumping posts when you don't get an instant response)

I suggest you work through tutorials like these or these
Logged

Roy from ITCrowd: Have you tried turning it off an on again?
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
Quote
because more often than not, i find myself copying code. i know very little about code.

I thought you did copy the code, and I'd actually question what you're learning by getting the forum to debug it line by line.

actually, i have learned a lot from this thread. already i know 10x more than i did before i started.

Quote
Quote
i figure since alot of people learn by just diving into it, i would try the same

An admirable approach except it's a way of drowning if you don't have a strong support group...
HI smiley-razz
Logged

Pages: 1 ... 3 4 [5] 6 7 8   Go Up
Jump to: