Uses a Sparkfun Thumb Joystick to control the X and Y coordinate returned from the mbed device acting as a HID based absolute mouse.
main.cpp@0:b2c327d045a2, 2011-11-18 (annotated)
- Committer:
- AdamGreen
- Date:
- Fri Nov 18 06:22:45 2011 +0000
- Revision:
- 0:b2c327d045a2
- Child:
- 2:ceb3218c3229
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:b2c327d045a2 | 15 | /* Uses two 10k potentiometers conntected to AnalogIn pins 15 and 16 to |
AdamGreen | 0:b2c327d045a2 | 16 | control the X and Y coordinate returned from the mbed device which is |
AdamGreen | 0:b2c327d045a2 | 17 | acting as HID based absolute mouse. |
AdamGreen | 0:b2c327d045a2 | 18 | */ |
AdamGreen | 0:b2c327d045a2 | 19 | #include <mbed.h> |
AdamGreen | 0:b2c327d045a2 | 20 | #include <USBMouse.h> |
AdamGreen | 0:b2c327d045a2 | 21 | |
AdamGreen | 0:b2c327d045a2 | 22 | int main(void) |
AdamGreen | 0:b2c327d045a2 | 23 | { |
AdamGreen | 0:b2c327d045a2 | 24 | static const float Width = (float)(X_MAX_ABS - X_MIN_ABS); |
AdamGreen | 0:b2c327d045a2 | 25 | static const float Height = (float)(Y_MAX_ABS - Y_MIN_ABS); |
AdamGreen | 0:b2c327d045a2 | 26 | AnalogIn AnalogX(p15); |
AdamGreen | 0:b2c327d045a2 | 27 | AnalogIn AnalogY(p16); |
AdamGreen | 0:b2c327d045a2 | 28 | USBMouse Mouse(ABS_MOUSE); |
AdamGreen | 0:b2c327d045a2 | 29 | |
AdamGreen | 0:b2c327d045a2 | 30 | while (1) |
AdamGreen | 0:b2c327d045a2 | 31 | { |
AdamGreen | 0:b2c327d045a2 | 32 | float AnalogXReading = AnalogX.read(); |
AdamGreen | 0:b2c327d045a2 | 33 | float AnalogYReading = AnalogY.read(); |
AdamGreen | 0:b2c327d045a2 | 34 | |
AdamGreen | 0:b2c327d045a2 | 35 | uint16_t X = X_MIN_ABS + (uint16_t)(Width * AnalogXReading); |
AdamGreen | 0:b2c327d045a2 | 36 | uint16_t Y = Y_MIN_ABS + (uint16_t)(Height * AnalogYReading); |
AdamGreen | 0:b2c327d045a2 | 37 | |
AdamGreen | 0:b2c327d045a2 | 38 | Mouse.move(X, Y); |
AdamGreen | 0:b2c327d045a2 | 39 | wait(0.01f); |
AdamGreen | 0:b2c327d045a2 | 40 | } |
AdamGreen | 0:b2c327d045a2 | 41 | } |