Last active
March 10, 2017 18:29
-
-
Save stephkoltun/9bc2872a4f3fdcb3b38eeed8f216acd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Paddle thisPaddle = players[indexVal]; | |
String control = thisPaddle.ctrl; | |
// base testing controller: potentiometer knob | |
if (control.equals("controllerZ")) { | |
int value = int(dataIn[0]); | |
thisPaddle.y = map(value, 0, 1023, 0, height); | |
} // end base controller | |
if (control.equals("controllerA")) { | |
// up down controls | |
// static move | |
int up = int(dataIn[0]); | |
int dn = int(dataIn[1]); | |
thisPaddle.constMove = false; | |
thisPaddle.increment = 20; | |
thisPaddle.h = height/7; | |
if (up == 1 && thisPaddle.upSpeed == 0) { | |
// make paddle go up by increment | |
thisPaddle.y = thisPaddle.y-(thisPaddle.increment+thisPaddle.adjIncrement); | |
thisPaddle.upSpeed = 1; // set value so button cannot be held | |
} else if (up == 0 && thisPaddle.upSpeed == 1) { | |
thisPaddle.upSpeed = 0; // reset so button can be pressed again | |
} | |
if (dn == 1 && thisPaddle.dnSpeed == 0) { | |
+ // make paddle go up by increment | |
+ thisPaddle.y = thisPaddle.y+(thisPaddle.increment+thisPaddle.adjIncrement); | |
+ thisPaddle.dnSpeed = 1; // set value so button cannot be held | |
+ } else if (dn == 0 && thisPaddle.dnSpeed == 1) { | |
+ thisPaddle.dnSpeed = 0; // reset so button can be pressed again | |
+ } | |
+ } // end controller A | |
+ | |
+ if (control.equals("controllerB")) { | |
+ // up down controls | |
+ // const move | |
+ int up = int(dataIn[0]); | |
+ int dn = int(dataIn[1]); | |
+ thisPaddle.constMove = true; | |
+ thisPaddle.increment = 3; | |
+ thisPaddle.h = 85; | |
+ | |
+ if (up == 1 && thisPaddle.upSpeed == 0) { | |
+ // go up | |
+ thisPaddle.upSpeed = 1; | |
+ thisPaddle.dnSpeed = 0; | |
+ } | |
+ if (dn == 1 && thisPaddle.dnSpeed == 0) { | |
+ // go up | |
+ thisPaddle.dnSpeed = 1; | |
+ thisPaddle.upSpeed = 0; | |
+ } | |
+ } // end controller B | |
+ | |
+ if (control.equals("controllerC")){ | |
+ // light switch | |
+ // constant movement | |
+ // photo cell | |
+ // bright = up | |
+ // dark = down | |
+ | |
+ int value = int(dataIn[0]); | |
+ thisPaddle.constMove = true; | |
+ thisPaddle.increment = 3; | |
+ thisPaddle.h = height/10; | |
+ | |
+ // calibrate to get ambient room for 2 seconds | |
+ while (millis() < thisPaddle.time + 1000) { | |
+ thisPaddle.ambientValue = thisPaddle.ambientValue*0.8 + value*0.2; | |
+ } | |
+ | |
+ if (value >= thisPaddle.ambientValue-100) { | |
+ thisPaddle.upSpeed = 1; | |
+ thisPaddle.dnSpeed = 0; | |
+ } else { | |
+ thisPaddle.dnSpeed = 1; | |
+ thisPaddle.upSpeed = 0; | |
+ } | |
+ } // end controller C | |
+ | |
+ if (control.equals("controllerD")) { | |
+ // flashlight | |
+ // constant movement | |
+ // photo cell | |
+ // bright = down | |
+ // dark = up | |
+ | |
+ int value = int(dataIn[0]); | |
+ thisPaddle.constMove = true; | |
+ thisPaddle.increment = 5; | |
+ thisPaddle.h = height/10; | |
+ | |
+ // calibrate to get ambient room for 2 seconds | |
+ while (millis() < thisPaddle.time + 1000) { | |
+ thisPaddle.ambientValue = thisPaddle.ambientValue*0.8 + value*0.2; | |
+ } | |
+ | |
+ if (value >= thisPaddle.ambientValue-50) { | |
+ thisPaddle.dnSpeed = 1; | |
+ thisPaddle.upSpeed = 0; | |
+ } else { | |
+ thisPaddle.upSpeed = 1; | |
+ thisPaddle.dnSpeed = 0; | |
+ } | |
+ } // end of controller D | |
+ | |
+ if (control.equals("controllerE")) { | |
+ // linear soft pot | |
+ // sequential position | |
+ // static | |
+ // short paddle | |
+ | |
+ thisPaddle.constMove = false; | |
+ thisPaddle.h = 80; | |
+ thisPaddle.increment = 150; | |
+ | |
+ int value = int(dataIn[0]); | |
+ | |
+ if (value != 0) { // contact is made, start measuring | |
+ if (thisPaddle.prevSlideValue == 0) { | |
+ // assign start | |
+ println("swipe started: " + value); | |
+ thisPaddle.swipeStart = value; | |
+ } else { | |
+ if (value > thisPaddle.prevSlideValue) { | |
+ thisPaddle.swipeEnd = value; | |
+ thisPaddle.prevSlideValue = value; | |
+ } | |
+ } | |
+ } else if (value == 0) { | |
+ // check if this means finger was lifted | |
+ if (thisPaddle.prevSlideValue != 0) { | |
+ println("swipe ended: " + thisPaddle.prevSlideValue); | |
+ thisPaddle.swipeEnd = thisPaddle.prevSlideValue; // final swipe value | |
+ int swipeLength = thisPaddle.swipeEnd - thisPaddle.swipeStart; | |
+ float stepValue = map(swipeLength, 0, 1023, 20, (thisPaddle.increment+thisPaddle.adjIncrement)); | |
+ println(stepValue); | |
+ thisPaddle.y = thisPaddle.y + stepValue; | |
+ if (thisPaddle.y > height) { | |
+ thisPaddle.y = height; | |
+ } | |
+ | |
+ if (thisPaddle.y < 0) { | |
+ thisPaddle.y = 0; | |
+ } | |
+ } | |
+ } | |
+ | |
+ thisPaddle.prevSlideValue = value; | |
+ myPorts[indexVal].clear(); | |
+ myPorts[indexVal].write('k'); | |
+ } // end controller E | |
+ | |
+ | |
+ if (control.equals("controllerF")) { | |
+ // toggle switch | |
+ // random position | |
+ // static | |
+ // long paddle | |
+ | |
+ int forward = int(dataIn[0]); | |
+ int backward = int(dataIn[1]); | |
+ | |
+ thisPaddle.h = height/7; | |
+ thisPaddle.constMove = false; | |
+ | |
+ if (forward != thisPaddle.prevForwardValue || backward != thisPaddle.prevBackValue) { | |
+ thisPaddle.prevValueOk = true; | |
+ } else { | |
+ thisPaddle.prevValueOk = false; | |
+ } | |
+ | |
+ if (thisPaddle.prevValueOk) { | |
+ if (forward == 1) { | |
+ if (thisPaddle.positionCounter < thisPaddle.positionsNon.length-1) { | |
+ thisPaddle.positionCounter++; | |
+ } else { | |
+ thisPaddle.positionCounter = 0; | |
+ } | |
+ } | |
+ | |
+ if (backward == 1) { | |
+ if (thisPaddle.positionCounter > 0) { | |
+ thisPaddle.positionCounter--; | |
+ } else { | |
+ thisPaddle.positionCounter = thisPaddle.positionsNon.length-1; | |
} | |
} | |
} | |
thisPaddle.prevForwardValue = forward; | |
thisPaddle.prevBackValue = backward; | |
thisPaddle.y = thisPaddle.positionsNon[thisPaddle.positionCounter]; | |
} // end controller F |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment