I'm trying to send multiple bits of data from the inputs from a joystick through
Radio Head 433Mhz Tx Rx. I still don't really understand the code and need help.
Transmitter
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
RH_ASK driver;
const int analogYpin = A7;
const int analogXpin = A6;
const int buttonPin = A5;
void setup()
{
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
pinMode(buttonPin, INPUT);
pinMode(analogYpin, INPUT);
pinMode(analogXpin, INPUT);
}
uint8_t data = 0;
void loop()
{
data = (uint8_t) (analogRead(buttonPin)/4); //Map from max of 1023 to 255
driver.send(&data, 1);
driver.waitPacketSent();
}
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
RH_ASK driver;
const int analogYpin = A7;
const int analogXpin = A6;
const int buttonPin = A5;
void setup()
{
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
pinMode(buttonPin, INPUT);
pinMode(analogYpin, INPUT);
pinMode(analogXpin, INPUT);
}
uint8_t data = 0;
void loop()
{
data = (uint8_t) (analogRead(buttonPin)/4); //Map from max of 1023 to 255
driver.send(&data, 1);
driver.waitPacketSent();
}
Receiver
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
RH_ASK driver;
void setup()
{
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
}
void loop()
{
uint8_t buflen = 3;
uint8_t buf[buflen];
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
Serial.print("Button Value: ");
Serial.println(*buf);
}
}
Thanks!