Uses a Sparkfun Thumb Joystick to control the X and Y coordinate returned from the mbed device acting as a HID based absolute mouse.

Dependencies:  

Committer:
AdamGreen
Date:
Wed Dec 07 07:27:31 2011 +0000
Revision:
2:ceb3218c3229
Parent:
0:b2c327d045a2
Modified to work with analog thumbstick and updated to latest mbed libraries.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AdamGreen 0:b2c327d045a2 1 /* Copyright 2011 Adam Green (http://mbed.org/users/AdamGreen/)
AdamGreen 0:b2c327d045a2 2
AdamGreen 0:b2c327d045a2 3 Licensed under the Apache License, Version 2.0 (the "License");
AdamGreen 0:b2c327d045a2 4 you may not use this file except in compliance with the License.
AdamGreen 0:b2c327d045a2 5 You may obtain a copy of the License at
AdamGreen 0:b2c327d045a2 6
AdamGreen 0:b2c327d045a2 7 http://www.apache.org/licenses/LICENSE-2.0
AdamGreen 0:b2c327d045a2 8
AdamGreen 0:b2c327d045a2 9 Unless required by applicable law or agreed to in writing, software
AdamGreen 0:b2c327d045a2 10 distributed under the License is distributed on an "AS IS" BASIS,
AdamGreen 0:b2c327d045a2 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AdamGreen 0:b2c327d045a2 12 See the License for the specific language governing permissions and
AdamGreen 0:b2c327d045a2 13 limitations under the License.
AdamGreen 0:b2c327d045a2 14 */
AdamGreen 2:ceb3218c3229 15 /* Uses a Sparkfun Thumb Joystick to control the X and Y coordinate returned
AdamGreen 2:ceb3218c3229 16 from the mbed device acting as a HID based absolute mouse.
AdamGreen 2:ceb3218c3229 17
AdamGreen 2:ceb3218c3229 18 More information about the analog joystick and associated breakout board can
AdamGreen 2:ceb3218c3229 19 be found at the following URL: http://www.sparkfun.com/products/10433
AdamGreen 2:ceb3218c3229 20
AdamGreen 2:ceb3218c3229 21 Connections
AdamGreen 2:ceb3218c3229 22 +-------------------+---------------+
AdamGreen 2:ceb3218c3229 23 | Joystick Breakout | mbed |
AdamGreen 2:ceb3218c3229 24 | VCC | pin 40 - VOUT |
AdamGreen 2:ceb3218c3229 25 | VERT | pin 15 - p15 |
AdamGreen 2:ceb3218c3229 26 | HORZ | pin 16 - p16 |
AdamGreen 2:ceb3218c3229 27 | SEL | Not Connected |
AdamGreen 2:ceb3218c3229 28 | GND | pin 1 - GND |
AdamGreen 2:ceb3218c3229 29 +-------------------+---------------+
AdamGreen 2:ceb3218c3229 30
AdamGreen 2:ceb3218c3229 31 The following notebook page shows how to connect a SparkFun USB breakout
AdamGreen 2:ceb3218c3229 32 board to mbed pin 31 (D+) & pin 32 (D-).
AdamGreen 2:ceb3218c3229 33 http://mbed.org/users/romilly/notebook/unboxing-the-lpc11u24/
AdamGreen 2:ceb3218c3229 34
AdamGreen 2:ceb3218c3229 35 Notebook page describing this program can be found here:
AdamGreen 2:ceb3218c3229 36 http://mbed.org/users/romilly/notebook/unboxing-the-lpc11u24/
AdamGreen 0:b2c327d045a2 37 */
AdamGreen 0:b2c327d045a2 38 #include <mbed.h>
AdamGreen 0:b2c327d045a2 39 #include <USBMouse.h>
AdamGreen 0:b2c327d045a2 40
AdamGreen 0:b2c327d045a2 41 int main(void)
AdamGreen 0:b2c327d045a2 42 {
AdamGreen 0:b2c327d045a2 43 static const float Width = (float)(X_MAX_ABS - X_MIN_ABS);
AdamGreen 0:b2c327d045a2 44 static const float Height = (float)(Y_MAX_ABS - Y_MIN_ABS);
AdamGreen 0:b2c327d045a2 45 AnalogIn AnalogX(p15);
AdamGreen 0:b2c327d045a2 46 AnalogIn AnalogY(p16);
AdamGreen 0:b2c327d045a2 47 USBMouse Mouse(ABS_MOUSE);
AdamGreen 0:b2c327d045a2 48
AdamGreen 0:b2c327d045a2 49 while (1)
AdamGreen 0:b2c327d045a2 50 {
AdamGreen 0:b2c327d045a2 51 float AnalogXReading = AnalogX.read();
AdamGreen 2:ceb3218c3229 52 float AnalogYReading = 1.0f - AnalogY.read();
AdamGreen 0:b2c327d045a2 53
AdamGreen 0:b2c327d045a2 54 uint16_t X = X_MIN_ABS + (uint16_t)(Width * AnalogXReading);
AdamGreen 0:b2c327d045a2 55 uint16_t Y = Y_MIN_ABS + (uint16_t)(Height * AnalogYReading);
AdamGreen 0:b2c327d045a2 56
AdamGreen 0:b2c327d045a2 57 Mouse.move(X, Y);
AdamGreen 0:b2c327d045a2 58 wait(0.01f);
AdamGreen 0:b2c327d045a2 59 }
AdamGreen 0:b2c327d045a2 60 }