Pages: 1 2 [3]   Go Down
Author Topic: Entering 3 digits  (Read 2621 times)
0 Members and 1 Guest are viewing this topic.
Delta, PA USA
Offline Offline
Newbie
*
Karma: 0
Posts: 30
I'm Lost !!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@PaulS...
There isn't any !!!!! LOL...

For my project, I really want to use the Arduino instead of the PLC.. But this language is a real bear for me to grasp.. Almost wish there were someone who wrote this stuff for a few bucks and a beer !!!LOL..

Its simple... enter 3 or 4 digits via keypad.. Push "*" to enter... Display the digits on LCD #1...Have Arduino energize a relay (Pin goes High)... Have rotary encoder input pulses... count pulses as they come in...Display the count on LCD #2... Have Arduino take pin Low when inputted digits match the rotary encoders count... Have a button to clear the rotary encoder count (stack) and the "#" key as a backspace or delete key for the numeric input from the keypad...

Is this a complicated sketch?.. Is it lengthly?

So far I have the keypad talking to the Arduino and the Keyed in digits sort of displaying on the LCD# 1... The rotary encoder is inputting the count but not working correctly.. Lots of bounce..

Hair is getting thinner by the evening with this project..

I appreciate all of the suggestions and help this community has provided.. I'm sure I will require ALOT more help before I'm done...
Logged

I'm Lost !! At least on the Arduino...

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

Quote
Almost wish there were someone who wrote this stuff for a few bucks and a beer !!!LOL..
There are, if the beer is good and cold. The problem is that you are the only one with the hardware.
Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 65
Posts: 2934
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, does the keypad finally work?
You have an encoder to input pulses, incrementally.
If the keypad data matches the encoder data, it triggers a relay.

What exactly are you making that would require 2 LCD screens, a rotary encoder and a keypad?

I'm just curious, that's all.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Delta, PA USA
Offline Offline
Newbie
*
Karma: 0
Posts: 30
I'm Lost !!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

HazardsMind... Its for a LARGE tubing bender in a private residence.. He is building a Mud truck and wants to bend a lot of tubing..

Its my brother so I'm attempting to help him out..

Sequence.. Figure out what angle he wants.. look on table, retrieve the two or three digit #( count from encoder, predetermined), enter the digits via the keypad, have digits appear on LCD#1 (for reference and verification), push the reset/clear key (separate push button,this clears the encoder count stack, resets to 0), Push the * key, This sets the first counter stack to digits entered via keypad, output pin goes high(relay attached to output pin to control motor), Rotary encoder is attached to the arm and outputs pulses as the arm moves (Pipe Bends), the count is displayed on LCD#2 to show the bend value... when the rotary encoder count matches the keypad # the output pin goes low and everything stops..

@PaulS..  As for the beer and hardware, Where do I send it to??..LOL (i'm serious.. I have two sets of hardware if your serious)

Logged

I'm Lost !! At least on the Arduino...

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

Send me a PM. I'll provide an address. I have time off after Christmas.
Logged

Delta, PA USA
Offline Offline
Newbie
*
Karma: 0
Posts: 30
I'm Lost !!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

HazardsMind.... yes the code works.. No more overflow..Ok.. Is there a way to show the digits on the display Before pushing the * key?.. I know I'm a pain in the Arse..
Logged

I'm Lost !! At least on the Arduino...

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

Quote
Is there a way to show the digits on the display Before pushing the * key?.
Yes. It's exactly the same as displaying them after the * key is pressed.
Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 65
Posts: 2934
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your not a pain in the arse, your like everyone else.You try really hard (on your own) for something to work, and when it doesn't you turn for help. Now what we do, is try to cross everything off the "to do list" before tackling another problem, that way we know that everything prior works. So I was basically crossing the keypad off.

Now as for displaying what you enter, that is relativly simple, but you will need to tweak the code a bit.

I can tell you what to put and where to put it, or I can take a crack at it myself, but again I dont know if it will work without any actual hardware to confirm that it does so. So I would rather you wrote it yourself and test it.

=========================================
In a nut shell what you want to see is this, if a number gets pressed, it shows on the LCD. If another number is pressed ,the cursor moves over and outputs the next number, same for the third number. Now with this, you can add the backspace if you want.

What you need to do is add the following under "Data[currentCommand++] = key;" in the IF statement //sorry, had to make an edit

 lcd.setCursor(6 + currentCommand,0); //  you need to insert "currentCommand" to move the cursor over for the next number.
 lcd.print(Data[currentCommand]);//then print it. Im not sure if this will output garbage, if it does let me know.

It would be a good idea to make a new sketch, copy/paste the working code and test THIS code out with it, rather than modify the one you have now. Reason why is because if this new code dont work, then you have the original code to try again.

Try this as a start.

NOTE, this is compiled, but not tested



« Last Edit: December 16, 2012, 03:20:30 pm by HazardsMind » Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Delta, PA USA
Offline Offline
Newbie
*
Karma: 0
Posts: 30
I'm Lost !!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I added the code as supplied.. The digits as entered are displayed as ---- (actually three horizontal lines in a stack) when inputted... When you push * it removes the dashes and displays the digits you hit..

The full code is included here:

/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
String keyIn;
int currentCommand = 0;


char Data[5];
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {28, 26, 24, 22}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {31, 33, 35}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
  lcd.begin(15,2);
}
 
void loop(){
  //lcd.begin(15,2);
  lcd.setCursor(2,0);
  lcd.print("Input Digits");

  char key = keypad.getKey();
if(key != NO_KEY) // Do nothing if no key is pressed, incorporated from PaulS's example.
  {
      if (key != '*') {
    Data[currentCommand++] = key;
    lcd.setCursor(6 + currentCommand,1);
    lcd.print(Data[currentCommand]);
   
}

else {
    int keyIn = atoi(Data);
    lcd.setCursor(6,1);
    lcd.print(keyIn);     
    lcd.print("     ");
    Serial.println(keyIn);
    while(currentCommand !=0){   // This can be used for any array size,
    Data[currentCommand--] = 0; //clear for new data
        }
     }
  }
}



I'm / We're gettin there !!

* KEYPAD_TEST_as_entered.ino (1.41 KB - downloaded 16 times.)
Logged

I'm Lost !! At least on the Arduino...

Queens, New York
Online Online
Faraday Member
**
Karma: 65
Posts: 2934
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quick question, why is keyIn declaired as a string at the top, but an int at the bottom? Make the one at the top the "int", and remove just "int" at the bottom.
also char Data[5]; should only be 2, not 5. umm, const byte COLS = 4; //should go back to 3, unless you plan on getting a 4x4 keypad, in which case you need to fix the numbers in char keys[ROWS][COLS]. You have a 15 by 2 LCD, I thought you had a 16 by 2 ?

ok, so you got "----" as the output when you entered the numbers but it was correct when you pressed " * ", weird. Ok try this,
Code:
void loop(){
  //lcd.begin(15,2);
  lcd.setCursor(2,0);
  lcd.print("Input Digits");

  char key = keypad.getKey();
if(key != NO_KEY) // Do nothing if no key is pressed, incorporated from PaulS's example.
  {
      if (key != '*') {
    Data[currentCommand++] = key;
    keyIn = atoi(Data);
    lcd.setCursor(6,1);
    lcd.print(keyIn);    //this should print the first digit in it's same spot and the 2nd and 3rd will follow like normal, when inputted.   
}

else {
     //keyIn = atoi(Data);
    //lcd.setCursor(6,1);
    //lcd.print(keyIn);
    //lcd.print("     ");     
    lcd.print(" OK");        //just to tell you * was pressed
    Serial.println(keyIn);
    while(currentCommand !=0){   // This can be used for any array size,
    Data[currentCommand--] = 0; //clear for new data
        }
     }
  }
}

Could you post a picture or little video of what your getting on the display?
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Delta, PA USA
Offline Offline
Newbie
*
Karma: 0
Posts: 30
I'm Lost !!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

PaulS.. It's on the way...
HazardsMind...The code is what I grabbed for a publication and I have tweaked it with your and PaulS's help..

I will attempt to get a screen shot for u..
Dave
Logged

I'm Lost !! At least on the Arduino...

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