Skip to content

Commit d5335d3

Browse files
committed
Added more Arduino examples to showcase how to access the controller's data, and how to setup the notification callback
1 parent 73f2cbb commit d5335d3

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

examples/Ps3Data/Ps3Data.ino

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <Ps3Controller.h>
2+
3+
bool stateIsConnected = false;
4+
5+
void setup()
6+
{
7+
Serial.begin(115200);
8+
Ps3.begin("01:02:03:04:05:06");
9+
Serial.println("Ready.");
10+
}
11+
12+
void loop()
13+
{
14+
if(stateIsConnected == false){
15+
16+
if (Ps3.isConnected()){
17+
delay(250); // ToDo: the ps3 library should handle this delay
18+
Ps3.setLed(1); // ToDo: the ps3 library should set LED 1 on connect by default
19+
stateIsConnected = true;
20+
}
21+
22+
}else{
23+
24+
if( Ps3.data.button.cross ){
25+
Serial.println("Pressing the cross button");
26+
}
27+
28+
if( Ps3.data.button.square ){
29+
Serial.println("Pressing the square button");
30+
}
31+
32+
if( Ps3.data.button.triangle ){
33+
Serial.println("Pressing the triangle button");
34+
}
35+
36+
if( Ps3.data.button.circle ){
37+
Serial.println("Pressing the circle button");
38+
}
39+
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <Ps3Controller.h>
2+
3+
bool stateIsConnected = false;
4+
5+
void notify()
6+
{
7+
if( Ps3.data.button.cross ){
8+
Serial.println("Pressing the cross button");
9+
}
10+
11+
if( Ps3.data.button.square ){
12+
Serial.println("Pressing the square button");
13+
}
14+
15+
if( Ps3.data.button.triangle ){
16+
Serial.println("Pressing the triangle button");
17+
}
18+
19+
if( Ps3.data.button.circle ){
20+
Serial.println("Pressing the circle button");
21+
}
22+
}
23+
24+
void setup()
25+
{
26+
Serial.begin(115200);
27+
Ps3.attach(notify);
28+
Ps3.begin("01:02:03:04:05:06");
29+
Serial.println("Ready.");
30+
}
31+
32+
void loop()
33+
{
34+
if(stateIsConnected == false){
35+
if (Ps3.isConnected()){
36+
delay(250); // ToDo: the ps3 library should handle this delay
37+
Ps3.setLed(1); // ToDo: the ps3 library should set LED 1 on connect by default
38+
stateIsConnected = true;
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)