Exiting Rainbow Fade Loop with IR Remote

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
rjenn2
 
Posts: 8
Joined: Thu Sep 22, 2022 3:22 pm

Exiting Rainbow Fade Loop with IR Remote

Post by rjenn2 »

I am having trouble exiting a loop with an IR remote.
This code is for a fading rainbow on an LED strip. The code should check the IR input during each pass of the for loop within the rainbow function. If the IR remote has received a signal from a specific button, it should turn off the LEDs.
Any feedback would be very helpful as I am very new to Arduino.
I am posting the whole code below but I believe the issue is likely in the rainbow function.

Code: Select all

#include <Adafruit_NeoPixel.h>
#include <IRremote.h>

#define IR_RECEIVER_PIN 6
IRrecv irreceive(IR_RECEIVER_PIN);

int inputPin = 3;
int pirState = LOW;
int val = 0;

decode_results results;

const int BorderRelay=4;

#define Border_PIXELPIN 2
#define Border_PIXELCOUNT 97 // Border

Adafruit_NeoPixel border(Border_PIXELCOUNT, Border_PIXELPIN, NEO_GRBW + NEO_KHZ800);

void setup() 
{
  Serial.begin(9600);
  irreceive.enableIRIn();
  pinMode(inputPin, INPUT);
  border.begin();
  border.show();
  pinMode(BorderRelay, OUTPUT);
}

void loop()
 {
  digitalWrite (BorderRelay, HIGH);

  val = digitalRead(inputPin);
  while (val == HIGH)
  {
  rainbow(10);
  }

  digitalWrite (BorderRelay, LOW);
}

void rainbow(uint8_t wait) 
{
  uint16_t i, j;

  for(j=0; j<256; j++) 
  {
    for(i=0; i<97; i++) 
    {
    border.setPixelColor(i, Wheel((i*1+j) & 255));
    }
    border.show();
    delay(wait);
    if(irreceive.decode(&results)) 
    {
      Serial.println(results.value, HEX);
      irreceive.resume();
    }
    if (results.value == 0XFD58A7)
    {
        border.clear();
        border.show();
        break;
    }
  }
}

uint32_t Wheel(byte WheelPos) 
{
  if(WheelPos < 85) 
  {
    return border.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } 
  else if(WheelPos < 170) 
  {
    WheelPos -= 85;
    return border.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } 
  else 
  {
    WheelPos -= 170;
    return border.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

User avatar
rjenn2
 
Posts: 8
Joined: Thu Sep 22, 2022 3:22 pm

Re: Exiting Rainbow Fade Loop with IR Remote

Post by rjenn2 »

Also, as you notice, this is on a motion detector. However, there is no motion when trying to turn off with the IR remote

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Exiting Rainbow Fade Loop with IR Remote

Post by adafruit_support_bill »

The problem is likely due to the fact that interrupts are disabled while writing to the pixel strip, so IR transmissions during that time period will be missed.

Depending on which processor you are using, you may be able to avoid the issue by using DMA to write to the pixels: https://learn.adafruit.com/dma-driven-neopixels

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”