RADIOHEAD questions again! Transmitter deciphering between 2 messages?

Hey guys! Got another RADIOHEAD programming question.

I’m using a little cheap 433 MHz receiver and 2 transmitters in this project. Each transmitter is sending its own unique message: the first one sends the message “X”, the second one sends the message “Y”, so we’ll call them Transmitter X and Y.

Both of these units are transmitting the messages non-stop while they are powered on, and will continue to do so until power is cut. The receiving unit is connected to an Adafruit Pro Trinket, which also has a soundboard and 2 LED’s connected to it. Each of the LED’s corresponds to one of the transmitters, so there’s lightX for Transmitter X, and lightY for Transmitter Y. What I’m trying to do is this: if power is cut from one of the transmitters, shut off its corresponding light and trigger the soundboard.

Since both transmitters are constantly sending a message, the lack of a message is what I’m trying to use to trip the light and soundboard.

Currently, this is what I’m doing to try to get that to happen. In the void Loop, I have variables I like to call the message check boxes (xcheck and ycheck). I initiate both xcheck and ycheck to be 0, then ask the device to listen for a message from both transmitters. If it recieves an X, xcheck = 1. If it receives a Y, ycheck is = 1. If both messages are coming in, then set both xcheck and ycheck to 1. Then, using “if” statements, depending on which messages were confirmed in the checking procedure, either turn the corresponding lights on or off, and trip the soundboard if one, or both, transmitters is dead.

To me the code looks like it should work, but whats happening is that if both transmitters are on, only one light stays on depending on which transmitter was switched on first, so I’m assuming in the “if (driver.recv(buf, &buflen))” is only looking at one of the message statements at a time and skipping the other, but I don’t know. Either that or the physics of 2 transmitters running at the same time will interfere and goof both messages.

Here’s the code for the transmitters. Note that the code for Transmitter X and Y are exactly the same, except the message is different.

#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile

RH_ASK driver(2000, 4, 8, 7);
int LED = 13;

void setup()
{
  pinMode(LED, OUTPUT);
    Serial.begin(9600);	  // Debugging only
    if (!driver.init())
         Serial.println("init failed");
         
}

void loop()
{
    const char *msg = "Y";
    digitalWrite(LED, HIGH);
    driver.send((uint8_t *)msg, strlen(msg));
    driver.waitPacketSent();  
}

And this is the code for the receiver.

#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile

RH_ASK driver(2000, 4, 8, 7);
int sound = 3;
int data = 4;
int lightX = 5;
int lightY = 6;
int xcheck = 0;
int ycheck = 0;

void setup()
{
  pinMode(sound, OUTPUT);
  pinMode(data, INPUT);
  pinMode(lightX, OUTPUT);
  pinMode(lightY, OUTPUT);
    Serial.begin(9600);	// Debugging only
    if (!driver.init())
         Serial.println("init failed");
  }

void loop()
{
    xcheck = 0;
    ycheck = 0;
    digitalWrite(sound, HIGH);
    uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
    uint8_t buflen = sizeof(buf);
  if (driver.recv(buf, &buflen)) // Check for messages and sort messages
  {
    if (buf[0] == 'X') { xcheck = 1; }
    if (buf[0] == 'Y') { ycheck = 1; }
  }
  
// Test values of x and ycheck, perform code
  if (xcheck == 1) { digitalWrite (lightX, HIGH); }
  if (xcheck == 0) { digitalWrite (lightX, LOW); digitalWrite (sound, LOW); }
  if (ycheck == 1) { digitalWrite (lightY, HIGH); }
  if (ycheck == 0) { digitalWrite (lightY, LOW); digitalWrite (sound, LOW); }
delay (200);
}

The wiring should also be 100% correct. It’s been absolutely perfect running several other variations of code. Let me know if there’s something that needs to be clarified.