Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #75 on: February 02, 2013, 12:33:50 am » |
@ Craftee
I'm sorry, but you haven't learnt the absolute basics, like how to write statements in C. I don't want to seem unhelpful, but you really need to learn a bit of that, before you start making something that sends keystrokes when buttons on an NES controller are pushed. You are trying to run, when you haven't learnt to crawl yet.
Statements in C end in a semicolon. Function calls have brackets. "if" and "else" are not function calls.
Things have to be done in sequence. You don't get out your raincoat, and then afterwards ask if it is raining.
Do some simpler examples, get the hang of programming, and it will reward you with being a lot less frustrating.
If you ask, on a line-by-line basis, how to fix things, you aren't learning, are you? You are just posting code, asking what is wrong, applying a one-line fix, and then moving onto the next line.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 67
|
 |
« Reply #76 on: February 02, 2013, 12:35:36 am » |
also, when i use the d-pad. it oddly types "W". nowhere in my code is there a "W"..........
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 67
|
 |
« Reply #77 on: February 02, 2013, 12:37:36 am » |
@ Craftee
I'm sorry, but you haven't learnt the absolute basics, like how to write statements in C. I don't want to seem unhelpful, but you really need to learn a bit of that, before you start making something that sends keystrokes when buttons on an NES controller are pushed. You are trying to run, when you haven't learnt to crawl yet.
Statements in C end in a semicolon. Function calls have brackets. "if" and "else" are not function calls.
Things have to be done in sequence. You don't get out your raincoat, and then afterwards ask if it is raining.
Do some simpler examples, get the hang of programming, and it will reward you with being a lot less frustrating.
If you ask, on a line-by-line basis, how to fix things, you aren't learning, are you? You are just posting code, asking what is wrong, applying a one-line fix, and then moving onto the next line.
lol i like the raincoat analogy. i might not be learning, but i do know more than i used to. better then nothing right?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 67
|
 |
« Reply #78 on: February 02, 2013, 12:42:55 am » |
also, when i use the d-pad. it oddly types "W". nowhere in my code is there a "W"..........
i fixed this with if ( output == 119 ) { Keyboard.press(KEY_UP_ARROW); } else Keyboard.release(KEY_UP_ARROW); before it was if ( output == 119 ) { Keyboard.press('up_arrow'); } else Keyboard.release('up_arrow'); but i still have the "a" button problem, where in the serial monitor it spams 127, instead of 0
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #79 on: February 02, 2013, 01:08:30 am » |
Keyboard.press('up_arrow');
This was always wrong, for two reasons. As your research has now shown (and congrats for doing it) you have to use KEY_UP_ARROW and not 'up_arrow'. Second, strings literals are in double quotes, not single quotes, so it should have been "up_arrow" (not 'up_arrow'). That is, assuming you wanted a string literal at all, which you really didn't. Since you are trying to squeeze a "character" literal into one byte, that accounts for why you saw "w" (which is the last letter in up_arro w).
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 67
|
 |
« Reply #80 on: February 02, 2013, 01:10:51 am » |
i think the reason why i cant isolate the "a" button is because i think the chip in the controller is doing math. for instance
the base number would be 127 - x (x being the value of the button)
so when i press the "a" button, in the serial monitor it comes out to 127 because 127 - 0 = 127 and therefor a = 0
when i press the "b" button, in the serial monitor it comes out to 126 because 127 - 1 = 126 and therefor b = 1
and so on.
im not sure how to approach this for a fix...
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 67
|
 |
« Reply #81 on: February 02, 2013, 01:12:04 am » |
This was always wrong, for two reasons. As your research has now shown (and congrats for doing it) you have to use KEY_UP_ARROW and not 'up_arrow'.
Second, strings literals are in double quotes, not single quotes, so it should have been "up_arrow" (not 'up_arrow'). That is, assuming you wanted a string literal at all, which you really didn't.
Since you are trying to squeeze a "character" literal into one byte, that accounts for why you saw "w" (which is the last letter in up_arrow).
ahh okay, thanks for the explanation
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #82 on: February 02, 2013, 01:13:17 am » |
if ( output == 119 ) { Keyboard.press(KEY_UP_ARROW); } else Keyboard.release(KEY_UP_ARROW); Wouldn't this make more sense? if ( output == 119 ) { Keyboard.press (KEY_UP_ARROW); Keyboard.release (KEY_UP_ARROW); } You only need to release the key after you've pressed it, don't you? What you had is like: if (phoneRings) answerPhone (); else hangUpPhone ();
But you don't need to hang up the phone if it hasn't rung!
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 67
|
 |
« Reply #83 on: February 02, 2013, 01:20:09 am » |
if ( output == 119 ) { Keyboard.press (KEY_UP_ARROW); Keyboard.release (KEY_UP_ARROW); } You only need to release the key after you've pressed it, don't you? What you had is like: if (phoneRings) answerPhone (); else hangUpPhone ();
But you don't need to hang up the phone if it hasn't rung! does this fix stuff? or does it just make the code more efficient?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #84 on: February 02, 2013, 01:22:41 am » |
I'm trying to teach you stuff here. Right now, by luck, it may work your way. Best to get things right though. It is the logical thought processes that will help you here. If your code was littered with stuff (as it is right now) like: Keyboard.release(KEY_UP_ARROW);
even when the key is not down ... you are just asking for future problems.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 67
|
 |
« Reply #85 on: February 02, 2013, 01:25:17 am » |
does this fix stuff? or does it just make the code more efficient?
okay i see what it did, but that wasnt the result i wanted. when i did it your way, the button was spamming ( it wasnt acting like a keyboard )
|
|
|
|
« Last Edit: February 02, 2013, 01:27:17 am by Craftee »
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #86 on: February 02, 2013, 01:25:41 am » |
Let me ask you this ... would you go around your house turning off light switches if they are already off?
No, you wouldn't, would you? And would you complain "hey, does it matter"? No. It is not logical to do it. That is the thing you have to learn.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #87 on: February 02, 2013, 01:26:19 am » |
it wasnt acting like a keyboard Try to think why. Please.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #88 on: February 02, 2013, 01:27:05 am » |
I know why it's doing it. But I want you to work it out. It's a learning process.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 67
|
 |
« Reply #89 on: February 02, 2013, 01:31:12 am » |
I know why it's doing it. But I want you to work it out. It's a learning process.
if ( output == 127 ) { Keyboard.press('a'); delay(1000); Keyboard.release('a'); } is this what you were thinking? i dont see anything else :/
|
|
|
|
|
Logged
|
|
|
|
|
|