Go Down

Topic: rc5-led (Read 904 times) previous topic - next topic

Jack

Hi all.

The led on pin3 must go on and off by a signal from my RC5 when i push on the number 1.
My program is not working.
What is wrong?
Regards,
                   Jack.

// rc5_2a ( febr. 2011)
#include <IRremote.h>
#include <IRremoteInt.h>

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

void setup()
{
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
  if (results.value = 1) {
    digitalWrite(ledPin,LOW);
    }
  else {
   
    digitalWrite(ledPin,HIGH);
    irrecv.resume(); // Receive the next value
  }
}

AlphaBeta

How does your program behave now? Does it print anything? If so; what?

Jack

Yess,it print the value in Hex from the key's a press, but the led on pin3 does nothing.
          Jack.

AlphaBeta

Code: [Select]
// rc5_2a ( febr. 2011)
#include <IRremote.h>
#include <IRremoteInt.h>

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

void setup()
{
 pinMode(ledPin, OUTPUT);
 Serial.begin(9600);
 irrecv.enableIRIn(); // Start the receiver
}

void loop() {
 if (irrecv.decode(&results)) {
   Serial.println(results.value, HEX);
   if (results.value = 1) {
     digitalWrite(ledPin,!digitalRead(ledPin));
   }

   irrecv.resume(); // Receive the next value
 }
}


How about that?

Jack

Hallo AlphaBeta.

There is progres but the led on pin3 is on by push on button 1 but also by push by all the other key's! The Serial monitor give's the good values.
What to do?
                    Jack.

AlphaBeta

Like this:
Code: [Select]
// rc5_2a ( febr. 2011)
#include <IRremote.h>
#include <IRremoteInt.h>

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

void setup()
{
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    if (results.value == 1) {
      digitalWrite(ledPin,!digitalRead(ledPin));
    }

    irrecv.resume(); // Receive the next value
  }
}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy