Basically I want to store a 4 digit number or smaller.
/* Keypadtest.pde
*
- Demonstrate the simplest use of the keypad library.
- The first step is to connect your keypad to the
- Arduino using the pin numbers listed below in
- rowPins[] and colPins[]. If you want to use different
- pins then you can change the numbers below to
- match your setup.
- Note: Make sure to use pullup resistors on each of
- the rowPins.
- Note: Pins are use multiple times in this example.
*/
#include <Keypad.h>
#include <LiquidCrystal.h>
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 9, 8, 7, 6 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10 };
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4, d5, d6, d7 on pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
void setup()
{
Serial.begin(9600);
}
char charGain[4];
int charindex =0;
void loop()
{
keyArray();
printArray();
}
void keyArray(){
for(charindex == 0;charindex < 4; charindex++){
char key = kpd.getKey();
if (key != NO_KEY){ //if there is any key being put
if (key = '#'){
for(charindex;charindex < 4;charindex++){ //if the user didn't enter 4 digits float from the keypad, then other char in the array is set to be 0
charGain[charindex]==0;
charindex==0;
}
}
else if (key = '*'){
else{ //if the user enter 0-9, then store it into array and display it
charGain[charindex]=key;
charindex++;
lcd.print(charGain[charindex]);
}
}
}
void printArray(){ //would like to show every char in the array after entering from keypad
for (charindex == 0;charindex < 4;charindex++){
//Serial.println("array [" ++ charindex ++ "]"++ charGain[charindex]);
lcd.print("array [");
delay (1000);
lcd.print(charindex);
delay (1000);
lcd.print("] ");
delay (1000);
lcd.print(charGain[charindex]);
delay (1000);
}
}
I looked at cutefatfat 's code to figure this much out, but I need to know how the number is ultimately stored, so I can multiply it by a different number and use it later.
Also I wanted the * key to cancel out all the digits of the code. If whoever helps me with this could explain it to me, so that I understand it and could do it on my own that would help a lot.