]> git.gir.st - tmk_keyboard.git/blob - protocol/usb_hid/USB_Host_Shield_2.0/examples/Bluetooth/PS3BT/PS3BT.ino
Squashed 'tmk_core/' changes from caca2c0..dc0e46e
[tmk_keyboard.git] / protocol / usb_hid / USB_Host_Shield_2.0 / examples / Bluetooth / PS3BT / PS3BT.ino
1 /*
2 Example sketch for the PS3 Bluetooth library - developed by Kristian Lauszus
3 For more information visit my blog: http://blog.tkjelectronics.dk/ or
4 send me an e-mail: kristianl@tkjelectronics.com
5 */
6
7 #include <PS3BT.h>
8 #include <usbhub.h>
9
10 // Satisfy the IDE, which needs to see the include statment in the ino too.
11 #ifdef dobogusinclude
12 #include <spi4teensy3.h>
13 #include <SPI.h>
14 #endif
15
16 USB Usb;
17 //USBHub Hub1(&Usb); // Some dongles have a hub inside
18
19 BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
20 /* You can create the instance of the class in two ways */
21 PS3BT PS3(&Btd); // This will just create the instance
22 //PS3BT PS3(&Btd, 0x00, 0x15, 0x83, 0x3D, 0x0A, 0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
23
24 bool printTemperature;
25 bool printAngle;
26
27 void setup() {
28 Serial.begin(115200);
29 #if !defined(__MIPSEL__)
30 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
31 #endif
32 if (Usb.Init() == -1) {
33 Serial.print(F("\r\nOSC did not start"));
34 while (1); //halt
35 }
36 Serial.print(F("\r\nPS3 Bluetooth Library Started"));
37 }
38 void loop() {
39 Usb.Task();
40
41 if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
42 if (PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117 || PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117 || PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117 || PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) {
43 Serial.print(F("\r\nLeftHatX: "));
44 Serial.print(PS3.getAnalogHat(LeftHatX));
45 Serial.print(F("\tLeftHatY: "));
46 Serial.print(PS3.getAnalogHat(LeftHatY));
47 if (PS3.PS3Connected) { // The Navigation controller only have one joystick
48 Serial.print(F("\tRightHatX: "));
49 Serial.print(PS3.getAnalogHat(RightHatX));
50 Serial.print(F("\tRightHatY: "));
51 Serial.print(PS3.getAnalogHat(RightHatY));
52 }
53 }
54
55 // Analog button values can be read from almost all buttons
56 if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
57 Serial.print(F("\r\nL2: "));
58 Serial.print(PS3.getAnalogButton(L2));
59 if (PS3.PS3Connected) {
60 Serial.print(F("\tR2: "));
61 Serial.print(PS3.getAnalogButton(R2));
62 }
63 }
64 if (PS3.getButtonClick(PS)) {
65 Serial.print(F("\r\nPS"));
66 PS3.disconnect();
67 }
68 else {
69 if (PS3.getButtonClick(TRIANGLE))
70 Serial.print(F("\r\nTraingle"));
71 if (PS3.getButtonClick(CIRCLE))
72 Serial.print(F("\r\nCircle"));
73 if (PS3.getButtonClick(CROSS))
74 Serial.print(F("\r\nCross"));
75 if (PS3.getButtonClick(SQUARE))
76 Serial.print(F("\r\nSquare"));
77
78 if (PS3.getButtonClick(UP)) {
79 Serial.print(F("\r\nUp"));
80 if (PS3.PS3Connected) {
81 PS3.setLedOff();
82 PS3.setLedOn(LED4);
83 }
84 }
85 if (PS3.getButtonClick(RIGHT)) {
86 Serial.print(F("\r\nRight"));
87 if (PS3.PS3Connected) {
88 PS3.setLedOff();
89 PS3.setLedOn(LED1);
90 }
91 }
92 if (PS3.getButtonClick(DOWN)) {
93 Serial.print(F("\r\nDown"));
94 if (PS3.PS3Connected) {
95 PS3.setLedOff();
96 PS3.setLedOn(LED2);
97 }
98 }
99 if (PS3.getButtonClick(LEFT)) {
100 Serial.print(F("\r\nLeft"));
101 if (PS3.PS3Connected) {
102 PS3.setLedOff();
103 PS3.setLedOn(LED3);
104 }
105 }
106
107 if (PS3.getButtonClick(L1))
108 Serial.print(F("\r\nL1"));
109 if (PS3.getButtonClick(L3))
110 Serial.print(F("\r\nL3"));
111 if (PS3.getButtonClick(R1))
112 Serial.print(F("\r\nR1"));
113 if (PS3.getButtonClick(R3))
114 Serial.print(F("\r\nR3"));
115
116 if (PS3.getButtonClick(SELECT)) {
117 Serial.print(F("\r\nSelect - "));
118 PS3.printStatusString();
119 }
120 if (PS3.getButtonClick(START)) {
121 Serial.print(F("\r\nStart"));
122 printAngle = !printAngle;
123 }
124 }
125 #if 0 // Set this to 1 in order to see the angle of the controller
126 if (printAngle) {
127 Serial.print(F("\r\nPitch: "));
128 Serial.print(PS3.getAngle(Pitch));
129 Serial.print(F("\tRoll: "));
130 Serial.print(PS3.getAngle(Roll));
131 }
132 #endif
133 }
134 #if 0 // Set this to 1 in order to enable support for the Playstation Move controller
135 else if (PS3.PS3MoveConnected) {
136 if (PS3.getAnalogButton(T)) {
137 Serial.print(F("\r\nT: "));
138 Serial.print(PS3.getAnalogButton(T));
139 }
140 if (PS3.getButtonClick(PS)) {
141 Serial.print(F("\r\nPS"));
142 PS3.disconnect();
143 }
144 else {
145 if (PS3.getButtonClick(SELECT)) {
146 Serial.print(F("\r\nSelect"));
147 printTemperature = !printTemperature;
148 }
149 if (PS3.getButtonClick(START)) {
150 Serial.print(F("\r\nStart"));
151 printAngle = !printAngle;
152 }
153 if (PS3.getButtonClick(TRIANGLE)) {
154 Serial.print(F("\r\nTriangle"));
155 PS3.moveSetBulb(Red);
156 }
157 if (PS3.getButtonClick(CIRCLE)) {
158 Serial.print(F("\r\nCircle"));
159 PS3.moveSetBulb(Green);
160 }
161 if (PS3.getButtonClick(SQUARE)) {
162 Serial.print(F("\r\nSquare"));
163 PS3.moveSetBulb(Blue);
164 }
165 if (PS3.getButtonClick(CROSS)) {
166 Serial.print(F("\r\nCross"));
167 PS3.moveSetBulb(Yellow);
168 }
169 if (PS3.getButtonClick(MOVE)) {
170 PS3.moveSetBulb(Off);
171 Serial.print(F("\r\nMove"));
172 Serial.print(F(" - "));
173 PS3.printStatusString();
174 }
175 }
176 if (printAngle) {
177 Serial.print(F("\r\nPitch: "));
178 Serial.print(PS3.getAngle(Pitch));
179 Serial.print(F("\tRoll: "));
180 Serial.print(PS3.getAngle(Roll));
181 }
182 else if (printTemperature) {
183 Serial.print(F("\r\nTemperature: "));
184 Serial.print(PS3.getTemperature());
185 }
186 }
187 #endif
188 }
Imprint / Impressum