Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EALib I2S LM75B SDFileSystem mbed
TestJoystick.cpp
00001 /* 00002 * Copyright 2013 Embedded Artists AB 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 /****************************************************************************** 00018 * Includes 00019 *****************************************************************************/ 00020 00021 #include "mbed.h" 00022 #include "TestJoystick.h" 00023 00024 /****************************************************************************** 00025 * Defines and typedefs 00026 *****************************************************************************/ 00027 00028 #define TIMEOUT (100) 00029 00030 /****************************************************************************** 00031 * Public Functions 00032 *****************************************************************************/ 00033 00034 bool TestJoystick::runTest() { 00035 DigitalIn up(p32); 00036 DigitalIn down(p38); 00037 DigitalIn left(p39); 00038 DigitalIn right(p37); 00039 DigitalIn center(p31); 00040 00041 printf("Reading joystick for %d seconds...\n", TIMEOUT/10); 00042 printf("Move it in all directions and click it!\n"); 00043 uint16_t mask = 0; 00044 00045 for (int i = 0; i < TIMEOUT; i++) { 00046 bool line = false; 00047 if (up.read() == 0) { printf("UP "); line = true; mask |= 0x01; } 00048 if (down.read() == 0) { printf("DOWN "); line = true; mask |= 0x02; } 00049 if (left.read() == 0) { printf("LEFT "); line = true; mask |= 0x04; } 00050 if (right.read() == 0) { printf("RIGHT "); line = true; mask |= 0x08; } 00051 if (center.read() == 0) { printf("CENTER ");line = true; mask |= 0x10; } 00052 if (line) { 00053 printf("\n"); 00054 } 00055 if (mask == 0x1F) { 00056 printf("All directions tested. Done!\n"); 00057 return true; 00058 } 00059 wait(0.1); 00060 if (i%10 == 0) { 00061 printf("%ds\n", (TIMEOUT-i)/10); 00062 } 00063 } 00064 printf("Failed to detect all joystick directions\n"); 00065 return false; 00066 } 00067 00068
Generated on Sun Jul 17 2022 08:29:10 by
1.7.2