I have been trying to make a simple circuit that wirelessly controls a motor with a potentiometer. I am using 315 rf transmitter and recievers. I am using a led in place of the motor for tests. I have got the code to transmit the data to the reciever but when it gets there, the led does fade brighter and lighter if I move the potentiometer but it keeps flashing. I have a theory that the flashing is because it takes too long to process but I don't know. I have spent many hours working on this I hope someone can help. Note some code I used off other videos and changed it to work for my thing. Here is the receiver code:
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>int pwmPin = 12; // assigns pin 12 to variable pwm
int c2 = 0; // declares variable c2String int_out;
int c11 = 0;// Create Amplitude Shift Keying Object
RH_ASK rf_driver;void setup()
{
// Initialize ASK Object
rf_driver.init();
// Setup Serial Monitor
pinMode(pwmPin, OUTPUT);
Serial.begin(9600);
}void loop()
{
// Set buffer to size of expected message
uint16_t data;
uint16_t xyz = data;
uint8_t datalen = sizeof(data);
if ( rf_driver.recv((uint8_t*)&data, &datalen)
&& datalen == sizeof(data))
{
c11 = data;
int c2 = 1024-c11;
Serial.println(c11);
digitalWrite(pwmPin, HIGH);
delayMicroseconds(c11);
digitalWrite(pwmPin, LOW);
delayMicroseconds(c2);
}
}