![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Slingshot Controller
Dependencies: ADXL345 DebounceIn USBDevice mbed
Diff: main.cpp
- Revision:
- 1:2721dc2acc2c
- Parent:
- 0:cf17ea89fd09
--- a/main.cpp Sun Oct 14 18:58:38 2012 +0000 +++ b/main.cpp Wed Oct 17 16:33:04 2012 +0000 @@ -18,13 +18,15 @@ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + Edited to use slider/pushbutton input instead of stretch sensor by Joshua Schrader and Brandon Yee, 2012 + */ #include "DebounceIn.h" #include "mbed.h" #include "USBMouse.h" #include "ADXL345.h" -//Serial pc(USBTX, USBRX); USBMouse mouse; ADXL345 accelerometer(p5, p6, p7, p8); @@ -32,7 +34,6 @@ DebounceIn button(p13); float str; int push; -// Physical interfaces BusOut leds(LED1, LED2, LED3, LED4); // Return slingshot angle in radians, up > 0 > down @@ -106,7 +107,6 @@ Timer timer; float angles[8] = {0}; - //float stretches[8] = {0}; while(1) { @@ -118,7 +118,6 @@ float this_angle = get_angle(); // apply some filtering - //float stretch = filter(stretches, 8, this_stretch); float angle = filter(angles, 8, this_angle); leds = state; @@ -133,13 +132,13 @@ break; case AIMING: - if(push) { // rapid de-stretch, considered a fire + if(push) { // push button while aiming, considered a fire mouse.release(MOUSE_LEFT); move_mouse(0, 0); timer.start(); wait(1); state = FIRING; - } else { + } else { //incrementally move mouse int x = 0.0 - cos(angle) * stretch * 40; int y = sin(angle) * stretch * 40; move_mouse(x, y); @@ -147,8 +146,8 @@ break; case FIRING: - push = !button; - if(push) { + push = !button; //update button + if(push) { // if pushed, return to ready timer.stop(); timer.reset(); state = WAITING;