-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from TkfleBR/develop
Develop
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |