Loose RCSwitch interrupt while TM1637 display on

Hi all.
First i would apologize for my english.
So, i'm working on a countdown project.
The board is a Nano Clone. The display is a 4 digit 7 segments with a TM1637 driver. The reciever is a RF 443mhz.
I use RCSwitch librarie for the reciever. the transmitter is an alarm remote.
I use TM1637.h librarie for the 4 digit.
I use Millis() ofr my count down.

Everything works but when i display the countdown on the 4 digit i loose the interrupt of the reciever.
The countdown works fine with the display on.
The reciever interrupts well when the display on the 4 digit is off.

the pins used :

// 4 digit Module connection pins (Digital Pins)
#define CLK 3
#define DIO 4

//RF433 init 

mySwitch.enableReceive(0);

I think the problem comes from interrupts but i did not managed to find at that time.

Has someone one idea of the origin of the problem or a clue to go further in my research.

Please post your complete sketch

Hi,

Here is the code. There are still optimisation to but that’s not the problem :slight_smile:

#include <RCSwitch.h> //librairie du module 433
#include "TM1637.h" //librairie du driver du 7 segments

#define ON 1
#define OFF 0
#define hhmm 1 //0 pour afficher HH:MM et 1 pour MM:SS
// Module connection pins (Digital Pins)
#define CLK 3
#define DIO 4

int8_t TimeDisp[] = {0x00, 0x00, 0x00, 0x00}; //Tableau des 4 chiffres
unsigned char ClockPoint = 1;

int init_minutes = 3;
int init_secondes = 6;
int secondes;
unsigned long oneSecond = 1000UL;
unsigned long startTime;

bool Update;

RCSwitch mySwitch = RCSwitch();

TM1637 tm1637(CLK, DIO); //Objet tm1637


void setup() {

  Serial.begin(9600);
  mySwitch.enableReceive(0);
  tm1637.set(7); //0 éclairage faible réglable jusqu'à 7 le plus intense
  tm1637.init(); //Initialisation du driver
  tm1637.point(POINT_ON);
  secondes = init_secondes + 60 * init_minutes;
  Update = ON;
  TimeInit(init_minutes, init_secondes);
  TimeDisplay();

  Serial.print("Setup : millis() : ");
  Serial.println( millis() );

  Serial.print("Setup : startTime : ");
  Serial.println( startTime );
}

void loop() {

  if (mySwitch.available()) {

    long recievedValue = mySwitch.getReceivedValue();
    Serial.print("Received ");
    Serial.println( recievedValue );

    if (recievedValue == 16580656)//Stop le Chrono (cadenas fermé)
    {
      Update = false;
      Serial.println("Stop");
      delay(500);
    }
    if (recievedValue == 16580620)//Demarre / reprends le chrono (cadenas ouvert)
    {
      Update = true;
      Serial.println("Start");
      delay(500);

    }
    if (recievedValue == 16580800)//stop et reinitialise a 3 mintes (mute)
    {
      Update = false;
      secondes = 185;
      TimeInit(init_minutes, init_secondes);
      TimeDisplay();

      Serial.println("Reset");
      delay(500);
    }
    if (recievedValue == 16580611)// eclair
    {
      Serial.println("eclair");
    }
    mySwitch.resetAvailable();
  }

  if (Update == ON)
  {
    TimeUpdate();

  }
}

void TimeUpdate()
{
  if (ClockPoint)tm1637.point(POINT_ON);
  else tm1637.point(POINT_OFF); //OFF Pour clignotement
  if (millis() - startTime >= oneSecond)
  {
    Serial.print("timeupdate : millis() : ");
    Serial.println( millis() );

    Serial.print("timeupdate : startTime : ");
    Serial.println( startTime );
    secondes--;
    startTime += oneSecond;
    if (secondes == 0) {
      Serial.print("negatif");
      Update = OFF;
    }
    int displayMin = secondes / 60;
    int displaySec = secondes % 60;
    TimeInit(displayMin, displaySec);
    TimeDisplay();
  }
}
void TimeInit(int _minutes, int _secondes)
{
  TimeDisp[0] = _minutes / 10; //Affichage mm:ss
  TimeDisp[1] = _minutes % 10;
  TimeDisp[2] = _secondes / 10;
  TimeDisp[3] = _secondes % 10;
}
void TimeDisplay()
{
  Serial.print(TimeDisp[0]);
  Serial.print(TimeDisp[1]);
  Serial.print(":");
  Serial.print(TimeDisp[2]);
  Serial.println(TimeDisp[3]);
  //tm1637.display(TimeDisp);
}

Optimizations like making it compile.

This code isn't correct:

void TimeUpdate()
{
  if (ClockPoint)tm1637.point(POINT_ON);
  else tm1637.point(POINT_OFF); //OFF Pour clignotement
...

You need to have your if statement inside parenthesis... if( .... ) and you don't want a trailing ; afterwards

void TimeUpdate()
{
  if ( (ClockPoint)tm1637.point(POINT_ON) ) {
    // do nothing
  }
  else {
    tm1637.point(POINT_OFF); //OFF Pour clignotement
  }

You need to have your if statement inside parenthesis

The if condition needs to be, and is, inside parentheses. The body of the if and else blocks need to be in curly braces IF there is more than one statement in the body. There are not, so the braces are optional. OP choose not to use them.

OP, you should post links to all the libraries that you are using.

PaulS:
The if condition needs to be, and is, inside parentheses.

No, it is not. There is a missing parenthesis.

Hi. Thanks for your feedback.
I think there is no point in my issue with bracket usage or not in the if statement.
Brackets are optional if there is only one instruction to execute. It can help to make code more readable.

I use two librairies :

#include <RCSwitch.h> //librairie du module 433 :

#include <TM1637.h> //librairie du driver du 7 segments :
https://github.com/Seeed-Studio/Grove_4Digital_Display

blh64:
No, it is not. There is a missing parenthesis.

The condition is ClockPoint, and that IS in parentheses.

OP’s code, with one statement per line:

  if (ClockPoint)
    tm1637.point(POINT_ON);
  else 
    tm1637.point(POINT_OFF); //OFF Pour clignotement