Hi
I'm currently working on a project in which I have to control 2 servo motors with 2 potentiometers using 433Mhz rf transmitter and receiver.can anyone help me with a code that I can use to do same please.
I'm really running out of time please if anyone could help me please doo...!!! This is the code I wrote
Rxr code:
#include <VirtualWire.h>
const int numberOfAnalogPins = 2; // how many analog integer values to receive
int data[numberOfAnalogPins]; // the data buffer
// the number of bytes in the data buffer
const int dataBytes = numberOfAnalogPins * sizeof(int);
int val,val1;
byte msgLength = dataBytes;
void setup()
{
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
Serial.begin(9600);
Serial.println("Ready");
digitalWrite(9,HIGH);
digitalWrite(8,LOW);
digitalWrite(5,HIGH);
digitalWrite(4,LOW);
// Initialize the IO and ISR
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver
}
void loop()
{
if (vw_get_message((byte*)data, &msgLength)) // Non-blocking
{
Serial.println("Got: ");
if(msgLength == dataBytes)
{
for (int i = 0; i < numberOfAnalogPins; i++)
{
Serial.print("pin ");
Serial.print(i);
Serial.print("=");
Serial.println(data*);*
- if(i=0)*
- {*
_ val=data*;_
_ val=map(val,0,1023,0,255);_
_ analogWrite(9,val);_
_ }_
_ if(i=1)_
_ {*_
_ val1=data*;
val1=map(val1,0,1023,0,255);
analogWrite(5,val1);
}*_
* }*
* }*
* else*
* {*
* Serial.print("unexpected msg length of ");*
* Serial.println(msgLength);*
* }*
* Serial.println();*
* }*
}
Txr code:
#include <VirtualWire.h>
const int numberOfAnalogPins = 2; // how many analog pins to read
int data[numberOfAnalogPins]; // the data buffer
const int dataBytes = numberOfAnalogPins * sizeof(int); // the number of bytes
* // in the data buffer*
void setup()
{
* // Initialize the IO and ISR*
* vw_setup(2000); // Bits per sec*
}
void loop()
{
* int values = 0;*
* for(int i=0; i <= numberOfAnalogPins; i++)*
* {*
* // read the analog ports*
_ data = analogRead(i); // store the values into the data buffer
* }
send((byte)data, dataBytes);
* delay(1000); //send every second*
}
void send (byte *data, int nbrOfBytes)
{
* vw_send(data, nbrOfBytes);
vw_wait_tx(); // Wait until the whole message is gone*
}_