bug : pwm full di launcher
Dependencies: Motor PID Joystick_OrdoV5 mbed millis
Fork of MainProgram_BaseBaru by
Diff: PS3Arduino.txt
- Revision:
- 2:ac21a024ac80
- Parent:
- 0:9072e932503c
- Child:
- 12:e07c59c28c29
--- a/PS3Arduino.txt Sat Jun 06 06:19:06 2015 +0000 +++ b/PS3Arduino.txt Sat Jun 27 07:37:28 2015 +0000 @@ -7,23 +7,33 @@ /** Fanny Achmad Hindrarta **/ /** EL'12 - 13212076 **/ /** **/ -/** Last Update : 15 Januari 2015, 20.30 **/ +/** Last Update : 01 Februar1 2015, 20.30 **/ /*********************************************************************************************/ #include <PS3BT.h> #include <usbhub.h> +//#include <PS3USB.h> #include "Arduino.h" // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include <spi4teensy3.h> #endif + USB Usb; -/* You can create the instance of the class in two ways */ + +// Bluetooth +// You can create the instance of the class in two ways BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so -/* You can create the instance of the class in two ways */ +//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 +/* +// USB +// You can create the instance of the class in two ways +PS3USB PS3(&Usb); // This will just create the instance +//PS3USB 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 +*/ boolean printAngle; uint8_t state = 0; @@ -45,12 +55,20 @@ void setup_joystik() { - while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection + while (!Serial) // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection + { + Serial.write(0x88); + Serial.write(0x09); + } if (Usb.Init() == -1) { - Serial.print(F("\r\nOSC did not start")); - while (1); //halt + //Serial.print(F("\r\nOSC did not start")); + while (1) //halt + { + Serial.write(0x88); + Serial.write(0x09); + } } - Serial.print(F("\r\nPS3 USB Library Started")); + //Serial.print(F("\r\nPS3 USB Library Started")); } /*********************************************************************************************/ @@ -78,6 +96,7 @@ Serial.write(RY); Serial.write(LX); Serial.write(LY); + // Debug /* @@ -153,7 +172,8 @@ void loop() { button = 0; RL = 0; - + button_click=0; + RL_click=0; Usb.Task(); // Pembacaan data joystik dilakukan jika PS3 tersambung ke Arduino @@ -212,58 +232,52 @@ // Pembacaan dan penggabungan data segitiga, lingkaran, silang, kotak, atas, kanan, bawah, kiri // Data bernilai '1' hanya saat tombol pertama kali ditekan if(PS3.getButtonClick(TRIANGLE)){ - segitiga_click = !segitiga_click; + button_click = button_click + (0x1 << 0); } if(PS3.getButtonClick(CIRCLE)){ - lingkaran_click = !lingkaran_click; + button_click = button_click + (0x1 << 1); } if(PS3.getButtonClick(CROSS)){ - silang_click = !silang_click; + button_click = button_click + (0x1 << 2); } if(PS3.getButtonClick(SQUARE)){ - kotak_click = !kotak_click; + button_click = button_click + (0x1 << 3); } if(PS3.getButtonClick(UP)){ - atas_click = !atas_click; + button_click = button_click + (0x1 << 4); } if(PS3.getButtonClick(RIGHT)){ - kanan_click = !kanan_click; + button_click = button_click + (0x1 << 5); } if(PS3.getButtonClick(DOWN)){ - bawah_click = !bawah_click; + button_click = button_click + (0x1 << 6); } if(PS3.getButtonClick(LEFT)){ - kiri_click = !kiri_click; + button_click = button_click + (0x1 << 7); } - button_click = 0; - button_click = (segitiga_click << 0) + (lingkaran_click << 1) + (silang_click << 2) + (kotak_click << 3) + (atas_click << 4) + (kanan_click << 5) + (bawah_click << 6) + (kiri_click << 7); - if(PS3.getButtonClick(R1)){ - R1_click = !R1_click; + RL_click = RL_click + (0x1 << 0); } if(PS3.getButtonClick(R3)){ - R3_click = !R3_click; + RL_click = RL_click + (0x1 << 1); } if(PS3.getButtonClick(L1)){ - L1_click = !L1_click; + RL_click = RL_click + (0x1 << 2); } if(PS3.getButtonClick(L3)){ - L3_click = !L3_click; + RL_click = RL_click + (0x1 << 3); } if(PS3.getButtonClick(START)){ - START_click = !START_click; + RL_click = RL_click + (0x1 << 4); } if(PS3.getButtonClick(SELECT)){ - SELECT_click = !SELECT_click; + RL_click = RL_click + (0x1 << 5); } if(PS3.getButtonClick(PS)){ - PS_click = !PS_click; + RL_click = RL_click + (0x1 << 6); } - RL_click = 0; - RL_click = (R1_click << 0) + (R3_click << 1) + (L1_click << 2) + (L3_click << 3) + (START_click << 4) + (SELECT_click << 5) + (PS_click << 6); - // Tombol Analog LX = PS3.getAnalogHat(LeftHatX); LY = PS3.getAnalogHat(LeftHatY); @@ -272,12 +286,12 @@ aL2 = PS3.getAnalogButton(L2); aR2 = PS3.getAnalogButton(R2); + + kirimdatajoystik(); } else { // PS3 Disconnected Serial.write(0x88); Serial.write(0x09); } - - kirimdatajoystik(); - delay(5); -} \ No newline at end of file + delay(3); +}