Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
satsob
/
Robotite_ylesannete_projekt
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f4f6ef22
authored
Oct 04, 2020
by
satsob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nRF
parent
ca11ad07
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
nRF_BTLE_ReceiveData/nRF_BTLE_ReceiveData.ino
nRF_BTLE_ReceiveData/nRF_BTLE_ReceiveData.ino
0 → 100644
View file @
f4f6ef22
/* Include libraries */
#include <SPI.h>
#include <RF24.h>
#include <BTLE.h>
RF24
radio
(
9
,
10
);
// Create RF24 object to work with the RF24 library.
BTLE
btle
(
&
radio
);
// Create BTLE object to work with the BTLE library.
void
setup
()
{
/* Start the Serial and btle. */
Serial
.
begin
(
9600
);
// while (!Serial) { }
// Serial.println("BTLE advertisement receiver");
btle
.
begin
(
""
);
}
void
loop
()
{
String
str
=
""
;
// For collecting a string of values from different types of variables
/* Start listening. If data is received it is stored in the "buffer".
Then the received data is decoded and checked (CRC). */
Serial
.
print
(
"Listening... "
);
if
(
btle
.
listen
())
{
Serial
.
print
(
"Got payload: "
);
// If data is received, print "Got payload: "
// Store the received data into the buffer
for
(
uint8_t
i
=
2
;
i
<
(
btle
.
buffer
.
pl_size
)
-
6
;
i
++
)
{
str
+=
(
char
(
btle
.
buffer
.
payload
[
i
]));
// Serial.print(btle.buffer.payload[i],HEX); Serial.print(" "); // To receive data in HEX format
Serial
.
print
(
char
(
btle
.
buffer
.
payload
[
i
]));
Serial
.
print
(
" "
);
// To receive data in char format
}
// (Spam protection) only if string starts with "CustomName"
if
(
str
.
startsWith
(
PASSWORD
))
{
str
.
replace
(
PASSWORD
,
""
);
// (remove / replace) PASSWORD
// According to what data was sent, print the direction
if
((
char
(
str
.
charAt
(
2
)))
==
7
)
Serial
.
println
(
"RIGHT"
);
else
if
((
char
(
str
.
charAt
(
2
)))
==
6
)
Serial
.
println
(
"LEFT"
);
else
if
((
char
(
str
.
charAt
(
2
)))
==
5
)
Serial
.
println
(
"FORWARD"
);
else
if
((
char
(
str
.
charAt
(
2
)))
==
4
)
Serial
.
println
(
"BACKWARD"
);
}
}
// Serial.println("done.");
// btle.hopChannel();
}
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