From d4a35bc5b1079e5cd8eff8e2086edca4f8e96aba Mon Sep 17 00:00:00 2001 From: sableRaf Date: Wed, 19 Dec 2012 13:15:11 +0100 Subject: [PATCH 1/2] New processing example Detect if the controller is pointing up or down --- examples/processing/flip/flip.pde | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 examples/processing/flip/flip.pde diff --git a/examples/processing/flip/flip.pde b/examples/processing/flip/flip.pde new file mode 100644 index 00000000..4df6a309 --- /dev/null +++ b/examples/processing/flip/flip.pde @@ -0,0 +1,52 @@ + +// Import the PS Move API Package +import io.thp.psmove.*; + +PSMove [] moves; + +void setup() { + moves = new PSMove[psmoveapi.count_connected()]; + for (int i=0; i green + move.set_leds(0, glow, glow); + move.set_rumble(0); + } + else { // Pointing down -> flashing red + rumble + move.set_leds((int)random(255), 0, 0); + move.set_rumble(255); + } + move.update_leds(); +} + +boolean isFlipped(float ay, float my) { + if (ay<0 && my>0) return true; + return false; +} + From 7373834bbb82e478b5e7bcdbd1cb9431b25762d0 Mon Sep 17 00:00:00 2001 From: sableRaf Date: Wed, 19 Dec 2012 17:45:11 +0100 Subject: [PATCH 2/2] New Processing example (button_array) Using a moveButton class to create an array of buttons and variables to abstract the API calls. --- .../processing/button_array/button_array.pde | 130 ++++++++++++++++++ .../processing/button_array/moveButton.pde | 42 ++++++ 2 files changed, 172 insertions(+) create mode 100644 examples/processing/button_array/button_array.pde create mode 100644 examples/processing/button_array/moveButton.pde diff --git a/examples/processing/button_array/button_array.pde b/examples/processing/button_array/button_array.pde new file mode 100644 index 00000000..42f600e4 --- /dev/null +++ b/examples/processing/button_array/button_array.pde @@ -0,0 +1,130 @@ +/* +Create a button array to store the values and press status of each button/trigger + */ + +import io.thp.psmove.*; + +PSMove move; + +int triggerValue; +boolean isTriggerPressed, isMovePressed, isSquarePressed, isTrianglePressed, isCrossPressed, isCirclePressed, isStartPressed, isSelectPressed, isPsPressed; + +int rumbleLevel; + +color sphereColor; +int r, g, b; + +moveButton[] moveButtons = new moveButton[9]; // The move controller has 9 buttons + +void setup() { + move = new PSMove(); // We need one controller + sphereColor = color(0); // Default sphere color (0 means ligths off) + + moveInit(); // Create the buttons +} + +void draw() { + sphereColor = color(0, 255-triggerValue, triggerValue); + + if(isMovePressed) { + rumbleLevel = 255; + sphereColor = color(random(0,255), 0, 0); + } + else { + rumbleLevel = 0; + } + + moveUpdate(rumbleLevel, sphereColor); // Get the buttons value (trigger only) and presses, and update actuators/indicators +} + + +//------------------------------------------------------------- + +void moveInit() { + for (int i=0; i 0 + isMovePressed = moveButtons[1].getPressed(); + isSquarePressed = moveButtons[2].getPressed(); + isTrianglePressed = moveButtons[3].getPressed(); + isCrossPressed = moveButtons[4].getPressed(); + isCirclePressed = moveButtons[5].getPressed(); + isSelectPressed = moveButtons[6].getPressed(); + isStartPressed = moveButtons[7].getPressed(); + isPsPressed = moveButtons[8].getPressed(); + + move.set_rumble(_rumbleLevel); + + r = (int)red(_sphereColor); + g = (int)green(_sphereColor); + b = (int)blue(_sphereColor); + move.set_leds(r, g, b); + move.update_leds(); +} + diff --git a/examples/processing/button_array/moveButton.pde b/examples/processing/button_array/moveButton.pde new file mode 100644 index 00000000..06256804 --- /dev/null +++ b/examples/processing/button_array/moveButton.pde @@ -0,0 +1,42 @@ +class moveButton { + + int isPressed; + int value; // For analog buttons only (triggers) + PVector analog; // For analog sticks (navigation controller only) + + moveButton() { + isPressed = 0; + value = 0; + analog = new PVector(0,0); + } + + void press() { + isPressed = 1; + } + + void release() { + isPressed = 0; + } + + boolean getPressed() { + if(isPressed == 1) return true; + return false; + } + + void setValue(int _val) { + value = _val; + } + + int getValue() { + return value; + } + + void setAnalog(float _x, float _y) { + analog.x = _x; + analog.y = _y; + } + + PVector getAnalog() { + return analog; + } +};