sui77 / rc-switch

Arduino lib to operate 433/315Mhz devices like power outlet sockets.
1.94k stars 663 forks source link

RCSwitch ReceiveDemo_Simple Interrupt #391

Open LEDLIT1 opened 3 years ago

LEDLIT1 commented 3 years ago

Using my Arduino Uno, when I run the ReceiveDemo_Simple from the RCSwitch library, I can see info received in the serial monitor when I press any button on my RF remote. It works.

The problem I am having is receiving RF data while the Arduino Uno is controlling something else, like an LED animation. It doesn't show any response in the serial monitor other than the cylon "x". I thought that because the RCSwitch utilized interrupt 0 on pin #2 that button presses would not be missed, but I was mistaken.

Is there a way I can code this so I don't miss a button press using RCSwitch while other things are running?

Here is the code below. `// RCSwitch ReceiveDemo_Simple with FastLED cylon

include

include

RCSwitch mySwitch = RCSwitch();

define DATA_PIN 6 // LED strip DATAPIN

define NUM_LEDS 85

CRGB leds[NUM_LEDS];

void setup() { Serial.begin(9600); mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2 LEDS.addLeds<WS2813, DATA_PIN, RGB>(leds, NUM_LEDS); LEDS.setBrightness(84); }

void ReceiveDemo_Simple () { if (mySwitch.available()) {

Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );

mySwitch.resetAvailable();

} }

void cylon() { static uint8_t hue = 0; Serial.print("x"); // First slide the led in one direction for(int i = 0; i < NUM_LEDS; i++) { // Set the i'th led to red leds[i] = CHSV(hue++, 255, 255); // Show the leds FastLED.show(); // now that we've shown the leds, reset the i'th led to black // leds[i] = CRGB::Black; fadeall(); // Wait a little bit before we loop around and do it again delay(10); } Serial.print("x");

// Now go in the other direction.
for(int i = (NUM_LEDS)-1; i >= 0; i--) { // Set the i'th led to red leds[i] = CHSV(hue++, 255, 255); // Show the leds FastLED.show(); // now that we've shown the leds, reset the i'th led to black // leds[i] = CRGB::Black; fadeall(); // Wait a little bit before we loop around and do it again delay(10); } }

void fadeall() { for (int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }

void loop() { ReceiveDemo_Simple(); cylon(); }`

HAMXAZAHID commented 3 years ago

I am having the same issue. I am using ATTINY1614 and while the MCU is busy in another loop the Remote Button Press is not registered despite being on an interrupt pin.