Delta, PA USA
Offline
Newbie
Karma: 0
Posts: 30
I'm Lost !!
|
 |
« on: December 13, 2012, 06:28:55 pm » |
Nub here again.. I'm actually making progress with my project.. and thanks to all who have helped..As it stands now, I can enter digits but the display only displays 1 digit at a time.. What do I need to add to allow me to enter 3 digits from the keypad and have the three digits display on my LCD when I hit the * key.. The code I'm using is : /* @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); 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); } void loop(){ char key = keypad.getKey(); if (key){ lcd.begin(16,0); lcd.setCursor(6,0); lcd.print(key); lcd.print(" "); Serial.println(key); } }
|
|
|
|
|
Logged
|
I'm Lost !! At least on the Arduino...
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 29
Posts: 1586
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #1 on: December 13, 2012, 06:38:36 pm » |
Change your loop to this. void loop(){
char key = keypad.getKey(); if (key != '*'){ String keyIn += key; }
else { lcd.begin(16,0); lcd.setCursor(6,0); // int keyDisp = keyIn.toInt(); lcd.print(keyIn); // if you don't get the correct data, then uncomment previous line and change keyIn to keyDisp lcd.print(" "); Serial.println(keyIn); keyIn = ""; //clear for new data } } I made an edit
|
|
|
|
« Last Edit: December 13, 2012, 06:44:18 pm by HazardsMind »
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Delta, PA USA
Offline
Newbie
Karma: 0
Posts: 30
I'm Lost !!
|
 |
« Reply #2 on: December 13, 2012, 06:52:22 pm » |
added the new loop.. Now I get a compile error at the: String keyIn += Key line
HELP !!!!
|
|
|
|
|
Logged
|
I'm Lost !! At least on the Arduino...
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 29
Posts: 1586
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #3 on: December 13, 2012, 06:55:59 pm » |
declair "String keyIn" at the top of your code with everything else and delete "String" inside the loop.
I thought that might happen, sorry
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Delta, PA USA
Offline
Newbie
Karma: 0
Posts: 30
I'm Lost !!
|
 |
« Reply #4 on: December 13, 2012, 06:59:40 pm » |
I declared it ... Remarked out the string... now it just keeps erroring on anything added
|
|
|
|
|
Logged
|
I'm Lost !! At least on the Arduino...
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35566
Seattle, WA USA
|
 |
« Reply #5 on: December 13, 2012, 07:02:14 pm » |
Of course, using the String class to collect a fixed number of characters is not necessary. Doing so will make it difficult to implement a backspace key.
A 4 element char array and an index would be much better - 3 characters and a NULL terminator. Increment the index each time you add a character and NULL. Decrement the index each time the backspace key is pressed.
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 29
Posts: 1586
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #6 on: December 13, 2012, 07:12:29 pm » |
What errors did you get, copy and paste them.
Also where did you get the keypad library, could you post a link?
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 29
Posts: 1586
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #7 on: December 13, 2012, 07:26:45 pm » |
I dont understand why you got errors, but this compiled. Try it. /* @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;
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); } void loop(){
char key = keypad.getKey(); if (key != '*'){ keyIn += key; }
else { lcd.begin(16,0); lcd.setCursor(6,0); // int keyDisp = keyIn.toInt(); lcd.print(keyIn); // if you don't get the correct data, then uncomment previous line and change keyIn to keyDisp lcd.print(" "); Serial.println(keyIn); keyIn = ""; //clear for new data } } @PaulS What backspace button, the only buttons dcr_inc has are what is on that keypad. Unless dcr_inc uses "#" as the backspace button.
|
|
|
|
« Last Edit: December 13, 2012, 07:29:57 pm by HazardsMind »
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35566
Seattle, WA USA
|
 |
« Reply #8 on: December 13, 2012, 07:54:18 pm » |
What backspace button, the only buttons dcr_inc has are what is on that keypad. Unless dcr_inc uses "#" as the backspace button. There may not be a backspace key yet. But, eventually, OP may decide that one is needed. It's best to plan for what may be needed, not just what IS needed. A String to handle 3 character entry is just plain lazy.
|
|
|
|
|
Logged
|
|
|
|
|
Delta, PA USA
Offline
Newbie
Karma: 0
Posts: 30
I'm Lost !!
|
 |
« Reply #9 on: December 13, 2012, 08:01:52 pm » |
Ok.. I used the code that was last supplied,.. I un remarked the int keyDisp = keyIn.toInt(); line.. Now I get a 0 on the lcd when I input the * key.. The TX LED on the Mega stays on for approx 30 seconds.. No other key does any thing.. No digits show on the LCD or Term.. The code is exactly what was provided by HazardsMind
|
|
|
|
|
Logged
|
I'm Lost !! At least on the Arduino...
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 29
Posts: 1586
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #10 on: December 13, 2012, 08:03:09 pm » |
True, but it is less coding and less confusing. I always go with simple codes first, then make them more complex. That way if the more complex code doesn't work then I have something to fall back on.
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Central MN, USA
Offline
Faraday Member
Karma: 35
Posts: 5941
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #11 on: December 13, 2012, 08:03:28 pm » |
A String to handle 3 character entry is just plain lazy.
Do this instead of String char keyIn[6]; //If you want 5 digits. String is lazy and will crash your project due to leaky free().
|
|
|
|
|
Logged
|
|
|
|
|
Delta, PA USA
Offline
Newbie
Karma: 0
Posts: 30
I'm Lost !!
|
 |
« Reply #12 on: December 13, 2012, 08:08:24 pm » |
Folks, I am to say the least LOST.. What should I delete to add the: char keyLin[6];
Im sorry I'm so lost
|
|
|
|
|
Logged
|
I'm Lost !! At least on the Arduino...
|
|
|
|
Central MN, USA
Offline
Faraday Member
Karma: 35
Posts: 5941
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #13 on: December 13, 2012, 08:13:56 pm » |
OP,
Sorry for the confusion. I will make an attempt to provide a more complete code with the char keyIn version.
HazzardMind has forgotten that getKey can also return NoKey. You need to exclude no key situation so you won't attempt to fill String with NoKey or NOKEY.
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 29
Posts: 1586
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #14 on: December 13, 2012, 08:14:46 pm » |
Ok, I appologize for the code not working, but keep in mind that I do not have a keypad to test myself, so i'm relying on what dcr_inc is getting. I could probably simulate it with the serial monitor but thats about it. I don't have any tact buttons or the time to buy or make one right now, so all of this is theoretical.
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
|