Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
RF24
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
RF24
Commits
fd89aae4
Commit
fd89aae4
authored
Feb 20, 2016
by
Avamander
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #219 from TMRh20/revert-218-217_fix
parents
99ada7ba
df225d64
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
21 deletions
+12
-21
examples/GettingStarted/GettingStarted.ino
examples/GettingStarted/GettingStarted.ino
+12
-21
No files found.
examples/GettingStarted/GettingStarted.ino
View file @
fd89aae4
...
...
@@ -9,6 +9,9 @@
#include "RF24.h"
/****************** User Config ***************************/
/*** Set this radio as radio number 0 or 1 ***/
bool
radioNumber
=
0
;
/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24
radio
(
7
,
8
);
/**********************************************************/
...
...
@@ -18,11 +21,6 @@ byte addresses[][6] = {"1Node","2Node"};
// Used to control whether this node is sending or receiving
bool
role
=
0
;
/**
* Set the role (sending or receiving) and configure the transmission pipes.
*/
void
setRole
(
bool
role
);
void
setup
()
{
Serial
.
begin
(
115200
);
Serial
.
println
(
F
(
"RF24/examples/GettingStarted"
));
...
...
@@ -35,7 +33,13 @@ void setup() {
radio
.
setPALevel
(
RF24_PA_LOW
);
// Open a writing and reading pipe on each radio, with opposite addresses
setRole
(
0
);
if
(
radioNumber
){
radio
.
openWritingPipe
(
addresses
[
1
]);
radio
.
openReadingPipe
(
1
,
addresses
[
0
]);
}
else
{
radio
.
openWritingPipe
(
addresses
[
0
]);
radio
.
openReadingPipe
(
1
,
addresses
[
1
]);
}
// Start the radio listening for data
radio
.
startListening
();
...
...
@@ -122,12 +126,12 @@ if (role == 1) {
char
c
=
toupper
(
Serial
.
read
());
if
(
c
==
'T'
&&
role
==
0
){
Serial
.
println
(
F
(
"*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK"
));
setRole
(
1
)
;
// Become the primary transmitter (ping out)
role
=
1
;
// Become the primary transmitter (ping out)
}
else
if
(
c
==
'R'
&&
role
==
1
){
Serial
.
println
(
F
(
"*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK"
));
setRole
(
0
)
;
// Become the primary receiver (pong back)
role
=
0
;
// Become the primary receiver (pong back)
radio
.
startListening
();
}
...
...
@@ -136,16 +140,3 @@ if (role == 1) {
}
// Loop
void
setRole
(
bool
newRole
)
{
role
=
newRole
;
if
(
role
){
radio
.
openWritingPipe
(
addresses
[
1
]);
radio
.
openReadingPipe
(
1
,
addresses
[
0
]);
}
else
{
radio
.
openWritingPipe
(
addresses
[
0
]);
radio
.
openReadingPipe
(
1
,
addresses
[
1
]);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment