I have a keypad connected to my Arduino via a Keypad Encoder IC. It works well, returning a unique character for each key press. The IC is serially connected to pin 3.
I can display the unique number, but what I can’t do is the following:
if the number >> 6, do something.
Should I be using (DEC) or (char) or (BYTE)?
I would appreciate your help.
#include <NewSoftSerial.h>
NewSoftSerial mySerial(3,1);
int val;
void setup(){
Serial.begin(9600);
mySerial.begin(9600);
val == ((char)mySerial.read());
}
void loop(){
delay (200);
if (mySerial.available()) {
Serial.print((char)mySerial.read());
}
[glow] if ((val)>>(char),6) {
Serial.print("YES");[/glow]
}
delay (500);
}
However, regardless of what character is returned, "YES" is printed. What I am trying to achieve is if a character 1 is returned do something - if 2 is returned do something else....and so on
Try printing the value that is sent to the Arduino. It may not match the number on the key. If it is being sent '1' when the 1 key is pressed, the ASCII value for 1 is 49, which IS greater than 6.