Skip to content

Commit

Permalink
Merge pull request #4 from TkfleBR/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ArthurFleischman authored Oct 2, 2018
2 parents 1b3920e + 71cd5c9 commit 44875f6
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
40 changes: 40 additions & 0 deletions emitter.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <SPI.h>
#include<RF24.h>

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

}
51 changes: 51 additions & 0 deletions receiver.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include<SPI.h>
#include<RF24.h>
#include<Servo.h>

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);
}
}
}
}

0 comments on commit 44875f6

Please sign in to comment.