Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ask_receiver.pde
- // -*- mode: C++ -*-
- // Simple example of how to use RadioHead to receive messages
- // with a simple ASK transmitter in a very simple way.
- // Implements a simplex (one-way) receiver with an Rx-B1 module
- // Tested on Arduino Mega, Duemilanova, Uno, Due, Teensy, ESP-12
- #include <RH_ASK.h>
- #ifdef RH_HAVE_HARDWARE_SPI
- #include <SPI.h> // Not actually used but needed to compile
- #endif
- RH_ASK driver;
- // RH_ASK driver(2000, 4, 5, 0); // ESP8266 or ESP32: do not use pin 11 or 2
- // RH_ASK driver(2000, 3, 4, 0); // ATTiny, RX on D3 (pin 2 on attiny85) TX on D4 (pin 3 on attiny85),
- // RH_ASK driver(2000, PD14, PD13, 0); STM32F4 Discovery: see tx and rx on Orange and Red LEDS
- void setup()
- {
- pinMode(8, OUTPUT);
- digitalWrite(8, 0);
- #ifdef RH_HAVE_SERIAL
- Serial.begin(9600); // Debugging only
- #endif
- if (!driver.init())
- #ifdef RH_HAVE_SERIAL
- Serial.println("init failed");
- #else
- ;
- #endif
- }
- String message;
- void loop()
- {
- uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
- uint8_t buflen = sizeof(buf);
- if (driver.recv(buf, &buflen)) // Non-blocking
- {
- // Convert each element of buf to a string and concatenate them
- for (int i = 0; i < buflen; i++)
- {
- message += String(buf[i]);
- }
- // Print the resulting string
- Serial.println(message);
- }
- if (message == "49") {
- digitalWrite(8, 1);
- delay(1000);
- message="";
- }
- else {
- digitalWrite(8, 0);
- message="";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement