-2

私はCプログラミングが初めてで、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
  }
}

行: if (??? = stringAppleUp) ??? のどこにどの変数を入れるかわかりません は。

助けてくれてありがとう。意思

4

1 に答える 1

6

あなたは目標を考えすぎています。最初の 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 を見つけることができます

最後に、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
  }
}
于 2013-02-28T02:20:52.710 に答える