Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

A digital 1 turns the carrier on while a digital 0 turns tit off.


Sample Code


Code Block
#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

// ask_transmitter.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to transmit messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) transmitter with an TX-C1 module

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

//RH_ASK (uint16_t speed=2000, uint8_t rxPin=11, uint8_t txPin=12, uint8_t pttPin=10, bool pttInverted=false)
RH_ASK driver(2000, D2, D1, D6); // ESP8266 or ESP32: do not use pin 11 or 2

//Connect data to pin 5/D1

void setup() 
{
    Serial.begin(115200);    
    Serial.println("\n\nRFnrfSender SnifferStarted\n\n");
    if (!driver.init()){
    mySwitch.enableReceive(0);  // Receiver input on interrupt 0 (GPIO 0)
  pinMode(LED_BUILTIN, OUTPUT);      Serial.println("init failed");
    }
    //driver.setModeTx();
    Serial.println("Initialized");
}

void loop() 
{
    Serial.println("Sending hello");
    const char *msg = "hello";

  if  (mySwitch.available()) {driver.send((uint8_t *)msg, strlen(msg));
    Serialdriver.print("Received ");
    Serial.print( mySwitch.getReceivedValue() );
    Serial.print("waitPacketSent();
    delay(1000);
}


Code Block
// 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

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

//RH_ASK (uint16_t speed=2000, uint8_t rxPin=11, uint8_t txPin=12, uint8_t pttPin=10, bool pttInverted=false)
RH_ASK driver(2000, D1, D2, D6); // ESP8266 or ESP32: do not use pin 11 or 2

//Connect data to pin 5/D1

void setup()
{
 / ");
    Serial.printbegin( mySwitch.getReceivedBitlength() );115200);    
    Serial.printprintln("Bit \n\nrfReceiver Started\n\n");
    if (!driver.init()){
         Serial.printprintln("init // failed");
    }
    Serial.printprintln("Protocol: Initialized");
    Serial.println( mySwitch.getReceivedProtocol() );
    digitalWrite(LED_BUILTIN, HIGH); // Toggle the onboard LED  

    delay(1
}

void loop()
{
    
    uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
    uint8_t buflen = sizeof(buf);

    if (driver.recv(buf, &buflen)) // Non-blocking
    {

      // Message with a good checksum received, dump it.
//      driver.printBuffer("Got:", buf, buflen);

    digitalWrite(LED_BUILTIN, LOW  Serial.print("Message Received: ");
    mySwitch.resetAvailable();
    Serial.println((char*)buf);  
      
    }
}


Reference

...