2013-02-27 73 views
-3

我是新來的c編程,並試圖比較IR HEX字符串。我越來越 - 錯誤:作爲賦值的左操作數所需的左值。IR HEX比較

我的東西我的問題是圍繞線路31 這裏是代碼:

/* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv 
* An IR detector/demodulator must be connected to the input RECV_PIN. 
* Version 0.1 July, 2009 
* Copyright 2009 Ken Shirriff 
* http://arcfn.com 
*/ 

#include <IRremote.h> 

int RECV_PIN = 11; 
IRrecv irrecv(RECV_PIN); 
decode_results results; 
String stringAppleUp; 



void setup() 
{ 

    Serial.begin(9600); 
    irrecv.enableIRIn(); // Start the receiver 
} 

void loop() { 

if (irrecv.decode(&results)) { 
    Serial.println(results.value, HEX); 
    Serial.println ("See it"); 
    stringAppleUp = string('77E150BC'); //apple remote up button 

if ( ????  = stringAppleUp) { 
    Serial.println("yes"); 
    } 
else 
    { 
    Serial.println("No"); 
    } 
irrecv.resume(); // Receive the next value 
    } 
} 

行:如果(??? = stringAppleUp) 我不知道把什麼變量,其中的???是。

感謝您的幫助。 將

+0

這功課嗎? – L0j1k 2013-02-27 13:21:30

+1

呃,我們應該怎麼知道你想放哪個變量?但是有兩個問題:'如果(a = b)'不檢查'a'是否等於'b',並且'string('77E150BC')'可能不會做你認爲的那樣。 – us2012 2013-02-27 13:22:43

+1

這是C還是C++? (問題的主體說C,所以我編輯了標籤,但看着代碼,我不確定。)無論如何,你可能在'if'條件下表示'==',而不是'='。 – geoffspear 2013-02-27 13:22:53

回答

5

你是在思考的目標。 第一個results.value返回一個uint32_t,而不是一個字符串。 其次,「字符串」不同於char數組(又名「字符串」)。注意資本S.

stringAppleUp = String('77E150BC'); 

,那麼你可以

String Foo = String('bar'); 
if (Foo == stringAppleUp) { 
... 

其中foo是你要測試的內容。值得注意的是「==」測試對的分配「=」

或者

char foo[] = "12345678"; 
if (strcmp(stringAppleUp, foo)) { 
... 

在這裏你可以找到strcmp of arrays here

最後,HEX不是一個字符串,而是一個整數。只需測試results.value。對另一個整數。

#include <IRremote.h> 

int RECV_PIN = 11; 
IRrecv irrecv(RECV_PIN); 
decode_results results; 

void setup() 
{ 

    Serial.begin(9600); 
    irrecv.enableIRIn(); // Start the receiver 
} 

void loop() { 

    if (irrecv.decode(&results)) { 
    Serial.print(F("result = 0x")); 
    Serial.println(results.value, HEX); 

    if (results.value == 0x77E150BC) { 
     Serial.println("yes"); 
    } 
    else { 
     Serial.println("No"); 
    } 
    irrecv.resume(); // Receive the next value 
    } 
}