Skip to content

Instantly share code, notes, and snippets.

@futureshocked
Created January 28, 2020 20:17
Show Gist options
  • Save futureshocked/19485984d96a0b8bfcc0a361e7fbc76f to your computer and use it in GitHub Desktop.
Save futureshocked/19485984d96a0b8bfcc0a361e7fbc76f to your computer and use it in GitHub Desktop.
();
Serial.print("Sending:");
Serial.print(message);
Serial.print(" ");
radio.write( &message, 1 );
// Now, continue listening
radio.startListening();
// Wait here until we get a response, or timeout (250ms)
unsigned long started_waiting_at = millis();
bool timeout = false;
while ( ! radio.available() && ! timeout )
if (millis() - started_waiting_at > 200 )
timeout = true;
// Describe the results
if ( timeout )
{
Serial.println("Failed, response timed out.");
}
else
{
// Grab the response, compare, and send to debugging spew
byte response;
radio.read( &response, sizeof(response) );
Serial.print("Transmitter. Received response from receiver:");
Serial.println(response,BIN);
if (response == B0)
{
digitalWrite(led_pin,HIGH);
Serial.println("Ok");
}
else
{
digitalWrite(led_pin,LOW);
Serial.println("No connection");
}
}
// Try again later
delay(150);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment