Keypad Char to String and String to Int
#include <Keypad.h>
const byte numRows= 4;
const byte numCols= 4;
String count;
int count2int ;
char keymap[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[numRows] = {9,8,7,6};
byte colPins[numCols]= {5,4,3,2};
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
void setup()
{
Serial.begin(9600);
}
void loop()
{
char keypressed = myKeypad.getKey();
if (keypressed != NO_KEY)
{
Serial.println(keypressed);
}
if(keypressed=='1'){ count = count+"1"; }
else if(keypressed=='2'){ count = count+"2"; }
else if(keypressed=='3'){ count = count+"3"; }
else if(keypressed=='4'){ count = count+"4"; }
else if(keypressed=='5'){ count = count+"5"; }
else if(keypressed=='6'){ count = count+"6"; }
else if(keypressed=='7'){ count = count+"7"; }
else if(keypressed=='8'){ count = count+"8"; }
else if(keypressed=='9'){ count = count+"9"; }
else if(keypressed=='0'){ count = count+"0"; }
else if(keypressed=='#')
{ count2int=0;
count2int = count.toInt();
count="";
}
Serial.print(count2int);
}
0 ความคิดเห็น:
แสดงความคิดเห็น
สมัครสมาชิก ส่งความคิดเห็น [Atom]
<< หน้าแรก