Last active
January 16, 2017 00:45
-
-
Save Lauszus/47db35874c08598c2b22 to your computer and use it in GitHub Desktop.
Example for controlling a servo using a PS3 controller
This file contains hidden or 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
| /* | |
| Example sketch for the PS3 Bluetooth library - developed by Kristian Lauszus | |
| For more information visit my blog: http://blog.tkjelectronics.dk/ or | |
| send me an e-mail: [email protected] | |
| */ | |
| #include <PS3BT.h> | |
| #include <SPI.h> | |
| #include <Servo.h> | |
| USB Usb; | |
| BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so | |
| /* You can create the instance of the class in two ways */ | |
| PS3BT PS3(&Btd); // This will just create the instance | |
| //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 | |
| Servo servo1; | |
| void setup() { | |
| Serial.begin(115200); | |
| if (Usb.Init() == -1) { | |
| Serial.print(F("\r\nOSC did not start")); | |
| while (1); //halt | |
| } | |
| Serial.print(F("\r\nPS3 Bluetooth Library Started")); | |
| servo1.attach(2); // Use pin 2 for the servo | |
| } | |
| void loop() { | |
| Usb.Task(); | |
| if (PS3.PS3Connected || PS3.PS3NavigationConnected) { | |
| if (PS3.getButtonClick(UP)) | |
| servo1.write(90); // Rotate 90 degrees if user presses UP | |
| if (PS3.getButtonClick(DOWN)) | |
| servo1.write(0); // Go back to 0 degrees if user presses DOWN | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment