16进制接收后做判断,这个问题一直困扰我。求助
String ck = "";while(Serial.available() > 0)
{
ck += char(Serial.read());
delay(2);
mark =1;
}
if(mark == 1)
{
if(ck==0x06A33A2EFF12){
fid = 0;
if(digitalRead(41)==HIGH){
delay(200);
fid = 1;
}else{
fid = 0;
}
switch(fid){
case 0: digitalWrite(41, LOW);break;
case 1: digitalWrite(41, HIGH);break;
}
delay(2);
}
}
ck = String("");
mark = 0;
串口接收16进制06A33A2EFF12后进入判断。调试的时候,出现一下错误。
zonghe:63: error: integer constant is too large for 'long' type
zonghe:79: error: integer constant is too large for 'long' type
zonghe:94: error: integer constant is too large for 'long' type
zonghe.ino: In function 'void loop()':
zonghe:63: error: invalid conversion from 'long long int' to 'const char*'
zonghe:63: error: initializing argument 1 of 'unsigned char String::operator==(const char*) const'
zonghe:79: error: invalid conversion from 'long long int' to 'const char*'
zonghe:79: error: initializing argument 1 of 'unsigned char String::operator==(const char*) const'
zonghe:94: error: invalid conversion from 'long long int' to 'const char*'
zonghe:94: error: initializing argument 1 of 'unsigned char String::operator==(const char*) const'
看样子是说ck这个数组长度不够。
不知道怎么定义让他够呢。
你还真够长的。。。。。你试试用某些GPS处理串口的方法试试? ck是字符串变量,而0x06A33A2EFF12是数值,二者不能直接比较判断相等,你需要把ck转换为数值后再比较。而且0x06A33A2EFF12是一个48bit的数值,也超过了长整形long存储32位(4字节)大小的变量。找本C语言的书看看就明白了 if(ck==0x06A33A2EFF12){
可改成if(ck.equals("06A33A2EFF12")){//----如果ck和"06A33A2EFF12"完全相符,就返回TRUE
或if(ck.equalsIgnoreCase("06A33A2EFF12")){//----和equal一样,但是不限制大小写
试试
页:
[1]