Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DirectionSolver{
- import oscP5.*;
- import netP5.*;
- OscP5 osc;
- float value;
- float totalV;
- int numReadings = 10;
- float runningTotal = 0;
- int thresh = 50;
- float[] readings = new float[numReadings];
- int index = 0;
- float average = 0;
- float currentRot = 0;
- DirectionSolver(){
- // initialize all the readings to 0:
- for (int thisReading = 0; thisReading < numReadings; thisReading++)
- readings[thisReading] = 0;
- // Listen to port
- osc = new OscP5(this, 12000);
- // Osc plug Function name Plug name
- // | | |
- osc.plug(this, "setValue", "/device/4/component/GyroZ");
- osc.plug(this, "resetRotation", "/device/4/component/Btn_MOVE");
- }
- void setValue(float theValue) {
- value = theValue;
- }
- void resetRotation(float moveButton){
- if(moveButton == 1.0)
- currentRot = 0;
- }
- void update(){
- runningTotal = runningTotal - readings[index];//subtract the last reading
- readings[index] = value;//read from OSC
- runningTotal = runningTotal+readings[index];//add the next position to the total
- index ++;
- if(index >= numReadings)
- index = 0;
- average = runningTotal / numReadings;
- currentRot += average;
- }
- float getDirection(){
- return currentRot;
- }
- }
Add Comment
Please, Sign In to add comment