Paul van der Wielen / Mbed 2 deprecated DigitalJoyStick

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002     Copyright (c) 2011 Pro-Serv
00003  
00004     Permission is hereby granted, free of charge, to any person obtaining a copy
00005     of this software and associated documentation files (the "Software"), to deal
00006     in the Software without restriction, including without limitation the rights
00007     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008     copies of the Software, and to permit persons to whom the Software is
00009     furnished to do so, subject to the following conditions:
00010  
00011     The above copyright notice and this permission notice shall be included in
00012     all copies or substantial portions of the Software.
00013  
00014     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020     THE SOFTWARE.
00021     
00022     Usage and assumptions:
00023         the digital joystick device is directly attached to the used pins as per
00024         function call, common contact to ground, using the internal pull-up's
00025         but one can use external pull-up's too or even a small capaitor if device
00026         shows signs of contact bounce.
00027         
00028     Operation modes:
00029         By default it's using dynamic mode which means that the main program may
00030         not see the expected pressed joystick contact in it's scan loop as another
00031         joystick contact may already be active.
00032         Using the static mode will capture the first joystick contact untill it's
00033         been read by the getJoyValue function
00034         
00035     To do:
00036         Adding a callable service routine to be used by the main program loop
00037  */
00038  
00039 #include "mbed.h"
00040 #include "joy.h"
00041 
00042 JoyRead  joy ( p21, p22, p23, p24, p25, PullUp); // center, 
00043 
00044 DigitalOut led1(LED1);
00045 
00046 int main() {
00047 
00048     // buffer first joystick movement, clear it upon read value
00049     joy.setJoyStatic(1);
00050 
00051     while(1) {
00052         if (joy.getJoyStatus()) {
00053             if (joy.getJoyKey(4)) {
00054                 printf("Joy Down is active\r\n");
00055             }
00056             printf("Joy value %x\r\n", joy.getJoyValue());
00057         }
00058         led1 = 0;
00059         wait(0.2);
00060         led1 = 1;
00061         wait(0.2);
00062     }
00063 }