[Resolved] Best way to interrupt my light bar's animations

Hi, it's me from the 74HC595 topic !

For the guys who helped me in this topic
the 0.1µF caps make a strange behaviour on my light bar so I removed them

Now, it's time to add the IR Receiver !
Which way is the best to make an interrut system with the IR ?

  • Serial Communication (Tried, worked but not optimized in my opinion)
  • Interrupt pin (3) (Tried and not working)
  • other ?


Libraries : ShiftRegisterPWM, IRRecv

It is best not to use Serial pins for stuff that does not use serial……

Why did you open a new thread rather than continue in the previous one?

1 Like

Please explain, how can a IR interrupt be added via Serial?

1 Like

Why did you open a new thread rather than continue in the previous one?

Because that's a question and not a problem

how can a IR interrupt be added via Serial?

With another Arduino board that sends serial data (that's why I think it's not optimized)

It is best not to use Serial pins for stuff that does not use serial……

Yes I agree ...

I don't think this a good idea.

Why don't use a interrupt dedicated pins - 2 or 3 ? (on Uno/Nano)

1 Like

Why don't use a interrupt dedicated pins - 2 or 3 (on Uno/Nano)

I've found some topics that say something about disabled interrupts because of uploading time
Also I've already tried to do this but didn't work

????
During an upload, not only interrupts are disabled - during this time, no code runs except the bootloader.

So show your code and connection diagram

1 Like

Connection diagram is at top of the topic ^^'

#define ShiftRegisterPWM_CLOCK_PORT PORTD
#define ShiftRegisterPWM_CLOCK_MASK 0B00100000

#include <IRremote.hpp>
#include <ShiftRegisterPWM.h>

ShiftRegisterPWM sr(3, 8);
IRrecv irrecv(3);
decode_results results;

bool hasReceivedIR = false;

void setup() {
  attachInterrupt(digitalPinToInterrupt(3), InterruptLightBar, RISING);

  pinMode(2, OUTPUT); // sr data pin
  pinMode(5, OUTPUT); // sr clock pin
  pinMode(4, OUTPUT); // sr latch pin

  irrecv.start();
  irrecv.enableIRIn();

  sr.interrupt(ShiftRegisterPWM::UpdateFrequency::Fast);

  for (int led = 0; led < 24; led++) {
    sr.set(led, 0);
  }
}

void loop() {
  hasReceivedIR = false;
LightBar();
}

void LightBar(){
  if (irrecv.decode(&results)){
    switch (results.value) {
      case 0xFFFFFFFF:
        for (int i = 0; i < 255; i++) {
          if (hasReceivedIR) return;
          for (int led = 0; led < 24; led++) {
            sr.set(led, i);
            if (hasReceivedIR) return;
          }
          if (hasReceivedIR) return;
        }
        break;
    }
  }
}

void InterruptLightBar(){
  hasReceivedIR = true;
}

Note that any variables, that should be changed inside the interrupt, must be declared as volatile.

Could you explain in more detail, what is nor works in the code?

Could you explain in more detail, what is nor works in the code?

Well uhh forgot some lines, now it's working by println debug (will be removed)

But the IRRecv library is kinda weird, the decode function is not defined (error at console) and the decode_results is deprecated ?? :cry:

Oh crap, the #include <IRemote.hpp> has been invisible until now ...
Changed to IRemote.h

Yes, it's been a long time
There should be a new example without using it in the library

I'll look at it :slightly_smiling_face:

Did you read a README file on the library repository?

Nop, I never know that the v2 is deprecated ...

There is v4 already :slight_smile:

1 Like

That's a big migration to do :sweat_smile:
Well anyways thank you for your help ! :blush:

Do you mean the recommended capacitor near the IC, wired from 5 volts to GND? One 0.1 uF cap per chip.

I'm not believing you tried that and it caused problems, please tell us more.

a7