Show how to control the light and rumble inside the PS4 controller

This commit is contained in:
Kristian Lauszus 2014-04-06 19:15:43 +02:00
parent 7e1feedbd1
commit d9dfa3cf35
2 changed files with 53 additions and 16 deletions

View file

@ -25,6 +25,7 @@ PS4BT PS4(&Btd, PAIR);
//PS4BT PS4(&Btd); //PS4BT PS4(&Btd);
boolean printAngle, printTouch; boolean printAngle, printTouch;
uint8_t oldL2Value, oldR2Value;
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
@ -56,28 +57,46 @@ void loop() {
Serial.print(F("\tR2: ")); Serial.print(F("\tR2: "));
Serial.print(PS4.getAnalogButton(R2)); Serial.print(PS4.getAnalogButton(R2));
} }
if (PS4.getAnalogButton(L2) != oldL2Value || PS4.getAnalogButton(R2) != oldR2Value) // Only write value if it's different
PS4.setRumbleOn(PS4.getAnalogButton(L2), PS4.getAnalogButton(R2));
oldL2Value = PS4.getAnalogButton(L2);
oldR2Value = PS4.getAnalogButton(R2);
if (PS4.getButtonClick(PS)) { if (PS4.getButtonClick(PS)) {
Serial.print(F("\r\nPS")); Serial.print(F("\r\nPS"));
PS4.disconnect(); PS4.disconnect();
} }
else { else {
if (PS4.getButtonClick(TRIANGLE)) if (PS4.getButtonClick(TRIANGLE)) {
Serial.print(F("\r\nTraingle")); Serial.print(F("\r\nTraingle"));
if (PS4.getButtonClick(CIRCLE)) PS4.setRumbleOn(RumbleLow);
}
if (PS4.getButtonClick(CIRCLE)) {
Serial.print(F("\r\nCircle")); Serial.print(F("\r\nCircle"));
if (PS4.getButtonClick(CROSS)) PS4.setRumbleOn(RumbleHigh);
}
if (PS4.getButtonClick(CROSS)) {
Serial.print(F("\r\nCross")); Serial.print(F("\r\nCross"));
if (PS4.getButtonClick(SQUARE)) PS4.setLedFlash(10, 10); // Set it to blink rapidly
}
if (PS4.getButtonClick(SQUARE)) {
Serial.print(F("\r\nSquare")); Serial.print(F("\r\nSquare"));
PS4.setLedFlash(0, 0); // Turn off blinking
}
if (PS4.getButtonClick(UP)) if (PS4.getButtonClick(UP)) {
Serial.print(F("\r\nUp")); Serial.print(F("\r\nUp"));
if (PS4.getButtonClick(RIGHT)) PS4.setLed(Red);
} if (PS4.getButtonClick(RIGHT)) {
Serial.print(F("\r\nRight")); Serial.print(F("\r\nRight"));
if (PS4.getButtonClick(DOWN)) PS4.setLed(Blue);
} if (PS4.getButtonClick(DOWN)) {
Serial.print(F("\r\nDown")); Serial.print(F("\r\nDown"));
if (PS4.getButtonClick(LEFT)) PS4.setLed(Yellow);
} if (PS4.getButtonClick(LEFT)) {
Serial.print(F("\r\nLeft")); Serial.print(F("\r\nLeft"));
PS4.setLed(Green);
}
if (PS4.getButtonClick(L1)) if (PS4.getButtonClick(L1))
Serial.print(F("\r\nL1")); Serial.print(F("\r\nL1"));

View file

@ -15,6 +15,7 @@ USB Usb;
PS4USB PS4(&Usb); PS4USB PS4(&Usb);
boolean printAngle, printTouch; boolean printAngle, printTouch;
uint8_t oldL2Value, oldR2Value;
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
@ -47,26 +48,43 @@ void loop() {
Serial.print(F("\tR2: ")); Serial.print(F("\tR2: "));
Serial.print(PS4.getAnalogButton(R2)); Serial.print(PS4.getAnalogButton(R2));
} }
if (PS4.getAnalogButton(L2) != oldL2Value || PS4.getAnalogButton(R2) != oldR2Value) // Only write value if it's different
PS4.setRumbleOn(PS4.getAnalogButton(L2), PS4.getAnalogButton(R2));
oldL2Value = PS4.getAnalogButton(L2);
oldR2Value = PS4.getAnalogButton(R2);
if (PS4.getButtonClick(PS)) if (PS4.getButtonClick(PS))
Serial.print(F("\r\nPS")); Serial.print(F("\r\nPS"));
if (PS4.getButtonClick(TRIANGLE)) if (PS4.getButtonClick(TRIANGLE)) {
Serial.print(F("\r\nTraingle")); Serial.print(F("\r\nTraingle"));
if (PS4.getButtonClick(CIRCLE)) PS4.setRumbleOn(RumbleLow);
}
if (PS4.getButtonClick(CIRCLE)) {
Serial.print(F("\r\nCircle")); Serial.print(F("\r\nCircle"));
if (PS4.getButtonClick(CROSS)) PS4.setRumbleOn(RumbleHigh);
}
if (PS4.getButtonClick(CROSS)) {
Serial.print(F("\r\nCross")); Serial.print(F("\r\nCross"));
if (PS4.getButtonClick(SQUARE)) PS4.setLedFlash(10, 10); // Set it to blink rapidly
}
if (PS4.getButtonClick(SQUARE)) {
Serial.print(F("\r\nSquare")); Serial.print(F("\r\nSquare"));
PS4.setLedFlash(0, 0); // Turn off blinking
}
if (PS4.getButtonClick(UP)) if (PS4.getButtonClick(UP)) {
Serial.print(F("\r\nUp")); Serial.print(F("\r\nUp"));
if (PS4.getButtonClick(RIGHT)) PS4.setLed(Red);
} if (PS4.getButtonClick(RIGHT)) {
Serial.print(F("\r\nRight")); Serial.print(F("\r\nRight"));
if (PS4.getButtonClick(DOWN)) PS4.setLed(Blue);
} if (PS4.getButtonClick(DOWN)) {
Serial.print(F("\r\nDown")); Serial.print(F("\r\nDown"));
if (PS4.getButtonClick(LEFT)) PS4.setLed(Yellow);
} if (PS4.getButtonClick(LEFT)) {
Serial.print(F("\r\nLeft")); Serial.print(F("\r\nLeft"));
PS4.setLed(Green);
}
if (PS4.getButtonClick(L1)) if (PS4.getButtonClick(L1))
Serial.print(F("\r\nL1")); Serial.print(F("\r\nL1"));