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: mbed-rtos mbed ssWi
joystick.hpp
00001 #ifndef __JOYSTICK_HPP__ 00002 #define __JOYSTICK_HPP__ 00003 00004 #include <limits> 00005 00006 #include "mbed.h" 00007 #include "rtos.h" 00008 00009 #define JOYSTICK_SX_X 1 00010 #define JOYSTICK_SX_Y 0 00011 #define JOYSTICK_DX_X 2 00012 #define JOYSTICK_DX_Y 3 00013 00014 class Joystick 00015 { 00016 00017 AnalogIn* channels[4]; 00018 float values[4]; 00019 Mutex mutexes[4]; 00020 00021 struct RangeJoystichChannel { 00022 float maxV; 00023 float minV; 00024 float center; 00025 RangeJoystichChannel () { 00026 maxV = std::numeric_limits<float>::min(); 00027 minV = std::numeric_limits<float>::max(); 00028 center = 0.0; 00029 } 00030 }; 00031 00032 RangeJoystichChannel ranges[4]; 00033 00034 void update(int channel); 00035 00036 public: 00037 00038 Joystick (PinName pinSX_X, PinName pinSX_Y, PinName pinDX_X, PinName pinDX_Y) { 00039 channels[JOYSTICK_SX_X] = new AnalogIn(pinSX_X); 00040 channels[JOYSTICK_SX_Y] = new AnalogIn(pinSX_Y); 00041 channels[JOYSTICK_DX_X] = new AnalogIn(pinDX_X); 00042 channels[JOYSTICK_DX_Y] = new AnalogIn(pinDX_Y); 00043 } 00044 00045 void tuneCentring (int nOfSamples, int channel); 00046 void tuneChannel (int nOfSamples, int channel); 00047 00048 void update(); 00049 00050 float read(int channel); 00051 00052 ~Joystick () { 00053 delete channels[JOYSTICK_SX_X]; 00054 delete channels[JOYSTICK_SX_Y]; 00055 delete channels[JOYSTICK_DX_X]; 00056 delete channels[JOYSTICK_DX_Y]; 00057 } 00058 }; 00059 00060 00061 #endif //__JOYSTICK_HPP__
Generated on Mon Jul 18 2022 23:15:17 by
1.7.2