Go Down

Topic: Little Help Guys! Arduino Programming (Read 1 time) previous topic - next topic

PaulS

Quote
To be honest, I don't fully understand what you have suggested to me(especially with timeouts and cycle stuffs) because I'm using and learning arduino for only about two weeks.

The problem that you need to solve is one of understanding whether or not the same switch is being pressed twice (2 -> 'a') quickly, or being pressed twice (2, 2). You need to also deal with other keys being pressed in the meantime. Pressing 2, 1, 2 quickly should NOT result in a, 1.

This really is not a beginner project.

PeterH

Suggest you step back from the problem and describe what you're trying to achieve. On one side of your solution you have a keypad that looks like a conventional phone keypad. It looks like you want to use this like a conventional phone keypad. Ignoring for the moment the magic that has to occur to figure out what character is being generated based on key presses, what is ultimately going to happen with the result - what's it for?
I only provide help via the forum - please do not contact me for private consultancy.

WizenedEE


Quote
To be honest, I don't fully understand what you have suggested to me(especially with timeouts and cycle stuffs) because I'm using and learning arduino for only about two weeks.

The problem that you need to solve is one of understanding whether or not the same switch is being pressed twice (2 -> 'a') quickly, or being pressed twice (2, 2). You need to also deal with other keys being pressed in the meantime. Pressing 2, 1, 2 quickly should NOT result in a, 1.

This really is not a beginner project.


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"

something like this:
Code: [Select]

#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
    pinMode(sensor, INPUT);
}

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);
}

kelvinsm



Quote
To be honest, I don't fully understand what you have suggested to me(especially with timeouts and cycle stuffs) because I'm using and learning arduino for only about two weeks.

The problem that you need to solve is one of understanding whether or not the same switch is being pressed twice (2 -> 'a') quickly, or being pressed twice (2, 2). You need to also deal with other keys being pressed in the meantime. Pressing 2, 1, 2 quickly should NOT result in a, 1.

This really is not a beginner project.


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"

something like this:
Code: [Select]

#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
    pinMode(sensor, INPUT);
}

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);
}



Thanks, I'll try this code.

kelvinsm


Quote
To be honest, I don't fully understand what you have suggested to me(especially with timeouts and cycle stuffs) because I'm using and learning arduino for only about two weeks.

The problem that you need to solve is one of understanding whether or not the same switch is being pressed twice (2 -> 'a') quickly, or being pressed twice (2, 2). You need to also deal with other keys being pressed in the meantime. Pressing 2, 1, 2 quickly should NOT result in a, 1.

This really is not a beginner project.


Yap, I haven't really thought that this is a beginner project.

Go Up