Hi everybody. I'm writing a program that, using a Keypad, reads the keypressed, store the value into an array num[4], than calculate the number NUM with 4 digits associated.
The problem: mapping the keypad with '1', '2', '3' etc. Arduino stores into num[] the ASCII value, that is 49, 50, 51 etc.
So I mapped the keypad with 1,2,3. WHAT ABOUT ZERO??? Mapping with 0, the keypad doesn't work, mapping with NULL I obtain nothing, what a mess!
Can someone help me?
Here is my code:
#include <Keypad.h>
int i;
int k;
int NUM;
int TIME;
int Time;
int Num;
int Num1;
int Time1;
int shut = 10; // pin scatto
const byte myRows = 4; // number of rows
const byte myCols = 3; //number of columns
char keys[myRows][myCols] = {
{1,2,3},
{4,5,6},
{7,8,9},
{'a',0,'c'} ////HERE IS THE PROBLEM
};
byte rowPins[myRows] = {7, 2, 3, 6 }; //array to map keypad to MCU pins
byte colPins[myCols] = {5, 8, 4 }; //array to map keypad to MCU pins
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, myRows, myCols ); //keypad library map function
int num[4];
int time[4];
void setup(){
pinMode(shut,OUTPUT);
digitalWrite(shut,LOW);
num[4]=0;
time[4]=0;
Serial.begin(9600);
for (int i=0; i<=3;){
//int num[4];
char key= keypad.getKey();
num *= key; *
- if (key!=NO_KEY){*
- if (key=='a' || key=='c'){*
- i=4; *
- }*
- if(key=='0'){ /// IS IT RIGHT?*
- key=atoi(0);*
- }*
- Serial.print(i);*
_ Serial.print(num*);_
_ i++; _
_ };*_
* if(key=='a' || key=='b' || i==4){*
* for(int k=0; k<=3;){*
* int kei= keypad.getKey();*
* //int time[4];*
* time[k]=kei;*
* if (kei!=NO_KEY){
_ Serial.print(k);_
_ k++;_
_ };_
_ if (time[k]==48){_
_ time[k]=0; _
_ }_
_ }_
_ i=4;_
_ }_
_ }*_
NUM = num[3]+num[2]*10+num[1]*100+num[0]*1000;
TIME = time[3]+time[2]*10+time[1]*100+time[0]*1000;
}
void loop(){
* for(int i=0; i<=NUM; i++){*
* digitalWrite(shut, HIGH);*
* delay(200);*
* digitalWrite(shut,LOW);*
* delay(TIME); *
* }*
}