Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass
Created June 21, 2020 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffersGlass/0d067c8bd49e4dd68e1ab33a9f6ff49c to your computer and use it in GitHub Desktop.
Save JeffersGlass/0d067c8bd49e4dd68e1ab33a9f6ff49c to your computer and use it in GitHub Desktop.
#include <Servo.h>
#include <RH_ASK.h>
#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h> // Not actually used but needed to compile
#endif
//RH_ASK driver; //Defaults to receive on pin D11 and transmit on pin 5
RH_ASK driver(2000, 11, 5, 0); //Bitrate, rx pin, tx pin, transmit controller pin
Servo servo1;
int servo1Pin = 2;
int ledPin = 5;
void setup()
{
servo1.attach(2);
pinMode(ledPin, OUTPUT);
#ifdef RH_HAVE_SERIAL
Serial.begin(9600); // Debugging only
delay(1000);
Serial.println("Beginning now");
#endif
if (!driver.init())
#ifdef RH_HAVE_SERIAL
Serial.println("init failed");
#else
;
#endif
}
void loop()
{
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
driver.printBuffer("Got:", buf, buflen);
int firstServoVal = buf[0];
int ledVal = buf[1];
Serial.print("First servo at:");
Serial.print(firstServoVal);
Serial.print("\tLED at:");
Serial.println(ledVal);
firstServoVal = map(firstServoVal, 0, 255, 0, 180);
servo1.write(firstServoVal);
ledVal = constrain(ledVal, 0, 255);
analogWrite(ledPin, ledVal);
//Message with a good checksum received, dump it in raw data
//driver.printBuffer("Got:", buf, buflen);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment