Pages: 1 [2]   Go Down
Author Topic: Little Help Guys! Arduino Programming  (Read 1375 times)
0 Members and 1 Guest are viewing this topic.
Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Keep in mind that pressing another key in between needs to reset the count of key presses. And, you need to deal, with some keys, like 3, where the user might want to produce "ee" that even the same key pressed more than once may, or may not, be trying to generate a new letter.

That is why the timing between keypresses is important.

Yes, can you give me example codes for timing that is related to my problem?
Logged

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

Quote
There doesn't need to be a timeout. So if you wanted to type "bb" you'd press "222<right>222" rather than "222<pause>222"
I think that would be "22<right>22", wouldn't it?

Then, to type "be", you'd type "2<right>33<right>". Do you really want to hit the right key after every letter?
Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
There doesn't need to be a timeout. So if you wanted to type "bb" you'd press "222<right>222" rather than "222<pause>222"
I think that would be "22<right>22", wouldn't it?
I believe OP originally said he wanted it to display 2 if pressed once. It is rather irrelevant though.
Quote
Then, to type "be", you'd type "2<right>33<right>". Do you really want to hit the right key after every letter?

Well in the code I posted, it would display the currently selected letter after anything other than a 2 was pressed... So "be" would be "2233"

Quote
Can you post your exact code?
Logged

Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here

Code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
int incr = 0;
char btn2 = 4;


void setup() 
{
    // use the ba ud rate your bluetooth module is configured to
    // not all baud rates are working well, i.e. ATMEGA168 works best with 57600
    Serial.begin(9600);
     Serial.println("Come at me baby!");
     mySerial.begin(9600);
     mySerial.println("Allright");
    // we initialize analog pin 5 as an input pin
   
}

void loop()
{
   
    char someChar;
    static char lastBtn = -1;
    static char lastChar = 0;
    static int numPresses = 0;
    if(digitalRead(btn2) == HIGH) {
        if (lastChar != 2) {
            if (lastChar != 0) mySerial.print(lastChar);
            numPresses = 0;
            lastBtn = 2;
        }
        someChar = '1';
        lastChar = 'a' + numPresses;
        numPresses++;
    }
    delay(100);
}
Logged

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

Code:
    // we initialize analog pin 5 as an input pin
We do? Please don't post code using that invisible font.

Code:
    if(digitalRead(btn2) == HIGH) {
This will NOT work, in any serious program. You need to detect transitions, not states. You need to know when the switch becomes pressed, not is pressed.

What, exactly, is someChar doing?

How IS the switch wired to pin 4?
Logged

Pages: 1 [2]   Go Up
Jump to: