Use a Sparkfun Blackberry Trackball Breakout Board as a mouse.

Dependencies:   mbed BBTrackball

Committer:
AdamGreen
Date:
Sun Dec 11 05:38:54 2011 +0000
Revision:
0:26bb60735515
Initial version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AdamGreen 0:26bb60735515 1 /* Copyright 2011 Adam Green (http://mbed.org/users/AdamGreen/)
AdamGreen 0:26bb60735515 2
AdamGreen 0:26bb60735515 3 Licensed under the Apache License, Version 2.0 (the "License");
AdamGreen 0:26bb60735515 4 you may not use this file except in compliance with the License.
AdamGreen 0:26bb60735515 5 You may obtain a copy of the License at
AdamGreen 0:26bb60735515 6
AdamGreen 0:26bb60735515 7 http://www.apache.org/licenses/LICENSE-2.0
AdamGreen 0:26bb60735515 8
AdamGreen 0:26bb60735515 9 Unless required by applicable law or agreed to in writing, software
AdamGreen 0:26bb60735515 10 distributed under the License is distributed on an "AS IS" BASIS,
AdamGreen 0:26bb60735515 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AdamGreen 0:26bb60735515 12 See the License for the specific language governing permissions and
AdamGreen 0:26bb60735515 13 limitations under the License.
AdamGreen 0:26bb60735515 14 */
AdamGreen 0:26bb60735515 15 /* Interfaces to a Sparkfun Blackberry Trackball Breakout Board and uses mbed's
AdamGreen 0:26bb60735515 16 USBMouse class to make it look like a mouse to a PC. Uses the trackball
AdamGreen 0:26bb60735515 17 motion to move the mouse pointer, pushing down on the trackball will trigger
AdamGreen 0:26bb60735515 18 a microswitch which will act as a left button click, and the LEDs under the
AdamGreen 0:26bb60735515 19 trackball will be lit different colours depending on what the user is
AdamGreen 0:26bb60735515 20 currently doing with the device (red for no motion, green when the trackball
AdamGreen 0:26bb60735515 21 is being moved, and blue during button clicks). It does use some other
AdamGreen 0:26bb60735515 22 utility classes from acceleration.h to provide acceleration to the trackball
AdamGreen 0:26bb60735515 23 motion.
AdamGreen 0:26bb60735515 24 */
AdamGreen 0:26bb60735515 25 #include <mbed.h>
AdamGreen 0:26bb60735515 26 #include <USBMouse.h>
AdamGreen 0:26bb60735515 27 #include "acceleration.h"
AdamGreen 0:26bb60735515 28
AdamGreen 0:26bb60735515 29
AdamGreen 0:26bb60735515 30
AdamGreen 0:26bb60735515 31 int main()
AdamGreen 0:26bb60735515 32 {
AdamGreen 0:26bb60735515 33 static USBMouse Mouse;
AdamGreen 0:26bb60735515 34 static CAcceleratedTrackball Trackball(p20, // BLU
AdamGreen 0:26bb60735515 35 p25, // RED
AdamGreen 0:26bb60735515 36 p26, // GRN
AdamGreen 0:26bb60735515 37 p10, // WHT
AdamGreen 0:26bb60735515 38 p5, // UP
AdamGreen 0:26bb60735515 39 p6, // DWN
AdamGreen 0:26bb60735515 40 p7, // LFT
AdamGreen 0:26bb60735515 41 p8, // RHT
AdamGreen 0:26bb60735515 42 p9); // BTN
AdamGreen 0:26bb60735515 43
AdamGreen 0:26bb60735515 44 for(;;)
AdamGreen 0:26bb60735515 45 {
AdamGreen 0:26bb60735515 46 int DeltaX;
AdamGreen 0:26bb60735515 47 int DeltaY;
AdamGreen 0:26bb60735515 48 int ButtonPressed;
AdamGreen 0:26bb60735515 49
AdamGreen 0:26bb60735515 50 Trackball.GetState(DeltaX, DeltaY, ButtonPressed);
AdamGreen 0:26bb60735515 51
AdamGreen 0:26bb60735515 52 Mouse.update(DeltaX,
AdamGreen 0:26bb60735515 53 DeltaY,
AdamGreen 0:26bb60735515 54 ButtonPressed ? MOUSE_LEFT : 0,
AdamGreen 0:26bb60735515 55 0);
AdamGreen 0:26bb60735515 56 }
AdamGreen 0:26bb60735515 57 }