Format PS3 examples

This commit is contained in:
Kristian Lauszus 2013-11-12 19:45:06 +01:00
parent 16c4272358
commit b50919b077
2 changed files with 173 additions and 193 deletions

View file

@ -22,20 +22,20 @@ void setup() {
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while(1); //halt
while (1); //halt
}
Serial.print(F("\r\nPS3 Bluetooth Library Started"));
}
void loop() {
Usb.Task();
if(PS3.PS3Connected || PS3.PS3NavigationConnected) {
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) {
if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
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) {
Serial.print(F("\r\nLeftHatX: "));
Serial.print(PS3.getAnalogHat(LeftHatX));
Serial.print(F("\tLeftHatY: "));
Serial.print(PS3.getAnalogHat(LeftHatY));
if(!PS3.PS3NavigationConnected) {
if (!PS3.PS3NavigationConnected) {
Serial.print(F("\tRightHatX: "));
Serial.print(PS3.getAnalogHat(RightHatX));
Serial.print(F("\tRightHatY: "));
@ -43,131 +43,131 @@ void loop() {
}
}
//Analog button values can be read from almost all buttons
if(PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
// Analog button values can be read from almost all buttons
if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
Serial.print(F("\r\nL2: "));
Serial.print(PS3.getAnalogButton(L2));
if(!PS3.PS3NavigationConnected) {
if (!PS3.PS3NavigationConnected) {
Serial.print(F("\tR2: "));
Serial.print(PS3.getAnalogButton(R2));
}
}
if(PS3.getButtonClick(PS)) {
if (PS3.getButtonClick(PS)) {
Serial.print(F("\r\nPS"));
PS3.disconnect();
}
else {
if(PS3.getButtonClick(TRIANGLE))
if (PS3.getButtonClick(TRIANGLE))
Serial.print(F("\r\nTraingle"));
if(PS3.getButtonClick(CIRCLE))
if (PS3.getButtonClick(CIRCLE))
Serial.print(F("\r\nCircle"));
if(PS3.getButtonClick(CROSS))
if (PS3.getButtonClick(CROSS))
Serial.print(F("\r\nCross"));
if(PS3.getButtonClick(SQUARE))
if (PS3.getButtonClick(SQUARE))
Serial.print(F("\r\nSquare"));
if(PS3.getButtonClick(UP)) {
if (PS3.getButtonClick(UP)) {
Serial.print(F("\r\nUp"));
if(PS3.PS3Connected) {
if (PS3.PS3Connected) {
PS3.setAllOff();
PS3.setLedOn(LED4);
}
}
if(PS3.getButtonClick(RIGHT)) {
if (PS3.getButtonClick(RIGHT)) {
Serial.print(F("\r\nRight"));
if(PS3.PS3Connected) {
if (PS3.PS3Connected) {
PS3.setAllOff();
PS3.setLedOn(LED1);
}
}
if(PS3.getButtonClick(DOWN)) {
if (PS3.getButtonClick(DOWN)) {
Serial.print(F("\r\nDown"));
if(PS3.PS3Connected) {
if (PS3.PS3Connected) {
PS3.setAllOff();
PS3.setLedOn(LED2);
}
}
if(PS3.getButtonClick(LEFT)) {
if (PS3.getButtonClick(LEFT)) {
Serial.print(F("\r\nLeft"));
if(PS3.PS3Connected) {
if (PS3.PS3Connected) {
PS3.setAllOff();
PS3.setLedOn(LED3);
}
}
if(PS3.getButtonClick(L1))
if (PS3.getButtonClick(L1))
Serial.print(F("\r\nL1"));
if(PS3.getButtonClick(L3))
if (PS3.getButtonClick(L3))
Serial.print(F("\r\nL3"));
if(PS3.getButtonClick(R1))
if (PS3.getButtonClick(R1))
Serial.print(F("\r\nR1"));
if(PS3.getButtonClick(R3))
if (PS3.getButtonClick(R3))
Serial.print(F("\r\nR3"));
if(PS3.getButtonClick(SELECT)) {
if (PS3.getButtonClick(SELECT)) {
Serial.print(F("\r\nSelect - "));
Serial.print(PS3.getStatusString());
}
if(PS3.getButtonClick(START)) {
if (PS3.getButtonClick(START)) {
Serial.print(F("\r\nStart"));
printAngle = !printAngle;
}
}
if(printAngle) {
if (printAngle) {
Serial.print(F("\r\nPitch: "));
Serial.print(PS3.getAngle(Pitch));
Serial.print(F("\tRoll: "));
Serial.print(PS3.getAngle(Roll));
}
}
else if(PS3.PS3MoveConnected) {
if(PS3.getAnalogButton(T)) {
else if (PS3.PS3MoveConnected) {
if (PS3.getAnalogButton(T)) {
Serial.print(F("\r\nT: "));
Serial.print(PS3.getAnalogButton(T));
}
if(PS3.getButtonClick(PS)) {
if (PS3.getButtonClick(PS)) {
Serial.print(F("\r\nPS"));
PS3.disconnect();
}
else {
if(PS3.getButtonClick(SELECT)) {
if (PS3.getButtonClick(SELECT)) {
Serial.print(F("\r\nSelect"));
printTemperature = !printTemperature;
}
if(PS3.getButtonClick(START)) {
if (PS3.getButtonClick(START)) {
Serial.print(F("\r\nStart"));
printAngle = !printAngle;
}
if(PS3.getButtonClick(TRIANGLE)) {
if (PS3.getButtonClick(TRIANGLE)) {
Serial.print(F("\r\nTriangle"));
PS3.moveSetBulb(Red);
}
if(PS3.getButtonClick(CIRCLE)) {
if (PS3.getButtonClick(CIRCLE)) {
Serial.print(F("\r\nCircle"));
PS3.moveSetBulb(Green);
}
if(PS3.getButtonClick(SQUARE)) {
if (PS3.getButtonClick(SQUARE)) {
Serial.print(F("\r\nSquare"));
PS3.moveSetBulb(Blue);
}
if(PS3.getButtonClick(CROSS)) {
if (PS3.getButtonClick(CROSS)) {
Serial.print(F("\r\nCross"));
PS3.moveSetBulb(Yellow);
}
if(PS3.getButtonClick(MOVE)) {
if (PS3.getButtonClick(MOVE)) {
PS3.moveSetBulb(Off);
Serial.print(F("\r\nMove"));
Serial.print(F(" - "));
Serial.print(PS3.getStatusString());
}
}
if(printAngle) {
if (printAngle) {
Serial.print(F("\r\nPitch: "));
Serial.print(PS3.getAngle(Pitch));
Serial.print(F("\tRoll: "));
Serial.print(PS3.getAngle(Roll));
}
else if(printTemperature) {
else if (printTemperature) {
Serial.print(F("\r\nTemperature: "));
Serial.print(PS3.getTemperature());
}

View file

@ -19,20 +19,20 @@ void setup() {
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while(1); //halt
while (1); //halt
}
Serial.print(F("\r\nPS3 USB Library Started"));
}
void loop() {
Usb.Task();
if(PS3.PS3Connected || PS3.PS3NavigationConnected) {
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) {
if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
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) {
Serial.print(F("\r\nLeftHatX: "));
Serial.print(PS3.getAnalogHat(LeftHatX));
Serial.print(F("\tLeftHatY: "));
Serial.print(PS3.getAnalogHat(LeftHatY));
if(!PS3.PS3NavigationConnected) {
if (!PS3.PS3NavigationConnected) {
Serial.print(F("\tRightHatX: "));
Serial.print(PS3.getAnalogHat(RightHatX));
Serial.print(F("\tRightHatY: "));
@ -40,121 +40,101 @@ void loop() {
}
}
// Analog button values can be read from almost all buttons
if(PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
Serial.print(F("\r\nL2: "));
Serial.print(PS3.getAnalogButton(L2));
if(!PS3.PS3NavigationConnected) {
if (!PS3.PS3NavigationConnected) {
Serial.print(F("\tR2: "));
Serial.print(PS3.getAnalogButton(R2));
}
}
if(PS3.getButtonClick(PS))
if (PS3.getButtonClick(PS))
Serial.print(F("\r\nPS"));
if(PS3.getButtonClick(TRIANGLE))
if (PS3.getButtonClick(TRIANGLE))
Serial.print(F("\r\nTraingle"));
if(PS3.getButtonClick(CIRCLE))
if (PS3.getButtonClick(CIRCLE))
Serial.print(F("\r\nCircle"));
if(PS3.getButtonClick(CROSS))
if (PS3.getButtonClick(CROSS))
Serial.print(F("\r\nCross"));
if(PS3.getButtonClick(SQUARE))
if (PS3.getButtonClick(SQUARE))
Serial.print(F("\r\nSquare"));
if(PS3.getButtonClick(UP)) {
if (PS3.getButtonClick(UP)) {
Serial.print(F("\r\nUp"));
PS3.setAllOff();
PS3.setLedOn(LED4);
}
if(PS3.getButtonClick(RIGHT)) {
if (PS3.getButtonClick(RIGHT)) {
Serial.print(F("\r\nRight"));
PS3.setAllOff();
PS3.setLedOn(LED1);
}
if(PS3.getButtonClick(DOWN)) {
if (PS3.getButtonClick(DOWN)) {
Serial.print(F("\r\nDown"));
PS3.setAllOff();
PS3.setLedOn(LED2);
}
if(PS3.getButtonClick(LEFT)) {
if (PS3.getButtonClick(LEFT)) {
Serial.print(F("\r\nLeft"));
PS3.setAllOff();
PS3.setLedOn(LED3);
}
if(PS3.getButtonClick(L1))
if (PS3.getButtonClick(L1))
Serial.print(F("\r\nL1"));
if(PS3.getButtonClick(L3))
if (PS3.getButtonClick(L3))
Serial.print(F("\r\nL3"));
if(PS3.getButtonClick(R1))
if (PS3.getButtonClick(R1))
Serial.print(F("\r\nR1"));
if(PS3.getButtonClick(R3))
if (PS3.getButtonClick(R3))
Serial.print(F("\r\nR3"));
if(PS3.getButtonClick(SELECT)) {
if (PS3.getButtonClick(SELECT)) {
Serial.print(F("\r\nSelect - "));
Serial.print(PS3.getStatusString());
}
if(PS3.getButtonClick(START)) {
if (PS3.getButtonClick(START)) {
Serial.print(F("\r\nStart"));
printAngle = !printAngle;
}
}
if(printAngle) {
if (printAngle) {
Serial.print(F("\r\nPitch: "));
Serial.print(PS3.getAngle(Pitch));
Serial.print(F("\tRoll: "));
Serial.print(PS3.getAngle(Roll));
}
else if(PS3.PS3MoveConnected) { // One can only set the color of the bulb, set the rumble, set and get the bluetooth address and calibrate the magnetometer via USB
switch(state) {
case 0:
}
else if (PS3.PS3MoveConnected) { // One can only set the color of the bulb, set the rumble, set and get the bluetooth address and calibrate the magnetometer via USB
if (state == 0) {
PS3.moveSetRumble(0);
PS3.moveSetBulb(Off);
state = 1;
break;
case 1:
} else if (state == 1) {
PS3.moveSetRumble(75);
PS3.moveSetBulb(Red);
state = 2;
break;
case 2:
} else if (state == 2) {
PS3.moveSetRumble(125);
PS3.moveSetBulb(Green);
state = 3;
break;
case 3:
} else if (state == 3) {
PS3.moveSetRumble(150);
PS3.moveSetBulb(Blue);
state = 4;
break;
case 4:
} else if (state == 4) {
PS3.moveSetRumble(175);
PS3.moveSetBulb(Yellow);
state = 5;
break;
case 5:
} else if (state == 5) {
PS3.moveSetRumble(200);
PS3.moveSetBulb(Lightblue);
state = 6;
break;
case 6:
} else if (state == 6) {
PS3.moveSetRumble(225);
PS3.moveSetBulb(Purble);
state = 7;
break;
case 7:
} else if (state == 7) {
PS3.moveSetRumble(250);
PS3.moveSetBulb(White);
state = 0;
break;
}
state++;
if (state > 7)
state = 0;
delay(1000);
}
}