init
This commit is contained in:
30
rf_rx/rf_rx.ino
Normal file
30
rf_rx/rf_rx.ino
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <RH_ASK.h>
|
||||
#include <SPI.h> // Required for RadioHead, though not used directly
|
||||
|
||||
// Initialize the RF receiver (default pin is 11, change if needed)
|
||||
RH_ASK rf_driver(2000, 17, 17); // 2000 bps, DATA pin on 17
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Good morning...");
|
||||
if (!rf_driver.init()) {
|
||||
Serial.println("RF Receiver initialization failed!");
|
||||
}
|
||||
|
||||
pinMode(32, OUTPUT);
|
||||
}
|
||||
|
||||
bool state = false;
|
||||
|
||||
void loop() {
|
||||
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN]; // Buffer for incoming message
|
||||
uint8_t buflen = sizeof(buf);
|
||||
|
||||
if (rf_driver.recv(buf, &buflen)) { // Check if a message is received
|
||||
buf[buflen] = '\0'; // Null-terminate the string
|
||||
Serial.print("Message received: ");
|
||||
Serial.println((char*)buf); // Print the received message
|
||||
state = !state;
|
||||
digitalWrite(32, state);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user