diff --git a/emitter.ino b/emitter.ino new file mode 100644 index 0000000..e8bb85f --- /dev/null +++ b/emitter.ino @@ -0,0 +1,40 @@ +#include +#include + +RF24 radio (7, 8); +struct package //struct of data to be sent +{ + + int valbx = 90; + int valby = 90; + +}data; + +byte addresses[][6] = {"0"}; //addresses + +int valx; //initializes values of horizontal and vertical servos +int valy; + +void setup() +{ + //radio setup + radio.begin(); + radio.setChannel(115); + radio.setPALevel(RF24_PA_MAX); + radio.setDataRate( RF24_250KBPS ) ; + radio.openWritingPipe(addresses[0]); + //end of radio setup +} + +void loop() +{ + + valx = analogRead(0); //potentiometer attached to A0 pin + valy = analogRead(1); //potentiometer attached to A1 pin + + valx = map(valx,0,1023,0,179); //mapping to the right values + valy = map(valy,0,1023,0,179); + + radio.write(&data,sizeof(data)); //sending data + +} diff --git a/receiver.ino b/receiver.ino new file mode 100644 index 0000000..3cf0a9d --- /dev/null +++ b/receiver.ino @@ -0,0 +1,51 @@ +#include +#include +#include + +Servo servox; +Servo servoy; + +RF24 radio (7, 8); + +struct package +{ + int valbx = 90; //that will make the camera allways start in right position, 90 degrees + int valby = 90; + +}data; + +byte addresses[][6] = {"0"}; + +int valx_before,valy_before; + +void setup() +{ + radio.begin(); + radio.setChannel(115); + radio.setPALevel(RF24_PA_MAX); + radio.setDataRate( RF24_250KBPS ) ; + radio.readingPipe(1,addresses[0]); + radio.startListening(); + + servox.attach(9); + servoy.attach(10); +} + +void loop() +{ + if(radio.available() + { + while(radio.available()) + { + radio.(&data,sizeof(data)); + valx_before = data.valx; + valy_before = data.valy; + + if(data.valx != valx_before || data.valy != valy_before) + { + servox.write(data.valbx); + servoy.write(data.valby); + } + } + } +}