Library for 3.2'' uLcd Picaso Display4D system Picaso Serial Environment Command Set web: http://www.4dsystems.com.au/product/20/67/Processors_Graphics/PICASO/
Nunchuk.h@1:a74e42cf52b2, 2015-04-05 (annotated)
- Committer:
- adelino
- Date:
- Sun Apr 05 13:54:48 2015 +0000
- Revision:
- 1:a74e42cf52b2
PicasoLib version 2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
adelino | 1:a74e42cf52b2 | 1 | #ifndef NUNCHUK_H |
adelino | 1:a74e42cf52b2 | 2 | #define NUNCHUK_H |
adelino | 1:a74e42cf52b2 | 3 | |
adelino | 1:a74e42cf52b2 | 4 | #include "mbed.h" |
adelino | 1:a74e42cf52b2 | 5 | |
adelino | 1:a74e42cf52b2 | 6 | /** Class to interface with a Nintendo wii Nunchuk. |
adelino | 1:a74e42cf52b2 | 7 | Exemple |
adelino | 1:a74e42cf52b2 | 8 | @code |
adelino | 1:a74e42cf52b2 | 9 | #include "mbed.h" |
adelino | 1:a74e42cf52b2 | 10 | #include "Nunchuk.h" |
adelino | 1:a74e42cf52b2 | 11 | |
adelino | 1:a74e42cf52b2 | 12 | Serial pc(USBTX,USBRX); |
adelino | 1:a74e42cf52b2 | 13 | Nunchuk device(p28,p27,0.05); |
adelino | 1:a74e42cf52b2 | 14 | int main() |
adelino | 1:a74e42cf52b2 | 15 | { |
adelino | 1:a74e42cf52b2 | 16 | while(1) { |
adelino | 1:a74e42cf52b2 | 17 | |
adelino | 1:a74e42cf52b2 | 18 | pc.printf("> :%d : %d : %d: %d \r\n",device.getJoyX(),device.getJoyY(),device.getAccX(),device.getBtnZ()); |
adelino | 1:a74e42cf52b2 | 19 | |
adelino | 1:a74e42cf52b2 | 20 | wait(1); |
adelino | 1:a74e42cf52b2 | 21 | } |
adelino | 1:a74e42cf52b2 | 22 | } |
adelino | 1:a74e42cf52b2 | 23 | @endcode |
adelino | 1:a74e42cf52b2 | 24 | */ |
adelino | 1:a74e42cf52b2 | 25 | |
adelino | 1:a74e42cf52b2 | 26 | class Nunchuk |
adelino | 1:a74e42cf52b2 | 27 | { |
adelino | 1:a74e42cf52b2 | 28 | |
adelino | 1:a74e42cf52b2 | 29 | public: |
adelino | 1:a74e42cf52b2 | 30 | /** Construct a Nunchuk object. |
adelino | 1:a74e42cf52b2 | 31 | * |
adelino | 1:a74e42cf52b2 | 32 | * @param sda I2C channel to use. |
adelino | 1:a74e42cf52b2 | 33 | * @param scl I2C channel |
adelino | 1:a74e42cf52b2 | 34 | * @param mTe the sampling time for the internal Ticker |
adelino | 1:a74e42cf52b2 | 35 | * if @param mTe=0 start a new acquisition manually without internal Ticker |
adelino | 1:a74e42cf52b2 | 36 | */ |
adelino | 1:a74e42cf52b2 | 37 | Nunchuk(PinName sda,PinName scl,float mTe=0); |
adelino | 1:a74e42cf52b2 | 38 | |
adelino | 1:a74e42cf52b2 | 39 | ~Nunchuk(void); |
adelino | 1:a74e42cf52b2 | 40 | |
adelino | 1:a74e42cf52b2 | 41 | /// start a new acquisition manually without internal Ticker |
adelino | 1:a74e42cf52b2 | 42 | void process(void); |
adelino | 1:a74e42cf52b2 | 43 | |
adelino | 1:a74e42cf52b2 | 44 | /// Get the joyStick position |
adelino | 1:a74e42cf52b2 | 45 | /// @returns -1: joyStick in left position |
adelino | 1:a74e42cf52b2 | 46 | /// @returns +1: joyStick in righ position |
adelino | 1:a74e42cf52b2 | 47 | /// @returns 0: center position |
adelino | 1:a74e42cf52b2 | 48 | |
adelino | 1:a74e42cf52b2 | 49 | |
adelino | 1:a74e42cf52b2 | 50 | signed char getJoyX(void); |
adelino | 1:a74e42cf52b2 | 51 | |
adelino | 1:a74e42cf52b2 | 52 | //! Get the joyStick position |
adelino | 1:a74e42cf52b2 | 53 | //! @returns -1: joyStick in left position |
adelino | 1:a74e42cf52b2 | 54 | //! @returns +1: joyStick in righ position |
adelino | 1:a74e42cf52b2 | 55 | //! @returns 0: center position |
adelino | 1:a74e42cf52b2 | 56 | |
adelino | 1:a74e42cf52b2 | 57 | signed char getJoyY(void); |
adelino | 1:a74e42cf52b2 | 58 | |
adelino | 1:a74e42cf52b2 | 59 | /** @returns The acceleration in axis X (10 bits) |
adelino | 1:a74e42cf52b2 | 60 | */ |
adelino | 1:a74e42cf52b2 | 61 | int getAccX(void); |
adelino | 1:a74e42cf52b2 | 62 | |
adelino | 1:a74e42cf52b2 | 63 | /** @returns The acceleration in axis Y (10 bits) |
adelino | 1:a74e42cf52b2 | 64 | */ |
adelino | 1:a74e42cf52b2 | 65 | int getAccY(void); |
adelino | 1:a74e42cf52b2 | 66 | |
adelino | 1:a74e42cf52b2 | 67 | /** @returns The acceleration in axis Z (10 bits) |
adelino | 1:a74e42cf52b2 | 68 | */ |
adelino | 1:a74e42cf52b2 | 69 | int getAccZ(void); |
adelino | 1:a74e42cf52b2 | 70 | |
adelino | 1:a74e42cf52b2 | 71 | |
adelino | 1:a74e42cf52b2 | 72 | //! @returns true if button C pressed |
adelino | 1:a74e42cf52b2 | 73 | |
adelino | 1:a74e42cf52b2 | 74 | bool getBtnC(void); |
adelino | 1:a74e42cf52b2 | 75 | |
adelino | 1:a74e42cf52b2 | 76 | |
adelino | 1:a74e42cf52b2 | 77 | //! @returns true if button Z pressed |
adelino | 1:a74e42cf52b2 | 78 | |
adelino | 1:a74e42cf52b2 | 79 | bool getBtnZ(void); |
adelino | 1:a74e42cf52b2 | 80 | |
adelino | 1:a74e42cf52b2 | 81 | /** @returns The sampling period |
adelino | 1:a74e42cf52b2 | 82 | */ |
adelino | 1:a74e42cf52b2 | 83 | float getPeriodeTe(void); |
adelino | 1:a74e42cf52b2 | 84 | |
adelino | 1:a74e42cf52b2 | 85 | |
adelino | 1:a74e42cf52b2 | 86 | |
adelino | 1:a74e42cf52b2 | 87 | protected: |
adelino | 1:a74e42cf52b2 | 88 | I2C myI2C; |
adelino | 1:a74e42cf52b2 | 89 | // |
adelino | 1:a74e42cf52b2 | 90 | Ticker myTicker; |
adelino | 1:a74e42cf52b2 | 91 | // |
adelino | 1:a74e42cf52b2 | 92 | bool setup(void); |
adelino | 1:a74e42cf52b2 | 93 | // |
adelino | 1:a74e42cf52b2 | 94 | bool request(void); |
adelino | 1:a74e42cf52b2 | 95 | // |
adelino | 1:a74e42cf52b2 | 96 | char decode(char data); |
adelino | 1:a74e42cf52b2 | 97 | // |
adelino | 1:a74e42cf52b2 | 98 | |
adelino | 1:a74e42cf52b2 | 99 | |
adelino | 1:a74e42cf52b2 | 100 | |
adelino | 1:a74e42cf52b2 | 101 | //datas |
adelino | 1:a74e42cf52b2 | 102 | static const int ADRESSE=0xA4; |
adelino | 1:a74e42cf52b2 | 103 | signed char joyX; //-1 0 +1 |
adelino | 1:a74e42cf52b2 | 104 | signed char joyY; //-1 0 +1 |
adelino | 1:a74e42cf52b2 | 105 | |
adelino | 1:a74e42cf52b2 | 106 | int accX; |
adelino | 1:a74e42cf52b2 | 107 | int accY; |
adelino | 1:a74e42cf52b2 | 108 | int accZ; |
adelino | 1:a74e42cf52b2 | 109 | |
adelino | 1:a74e42cf52b2 | 110 | bool btnC; |
adelino | 1:a74e42cf52b2 | 111 | bool btnZ; |
adelino | 1:a74e42cf52b2 | 112 | |
adelino | 1:a74e42cf52b2 | 113 | float periodeTe; |
adelino | 1:a74e42cf52b2 | 114 | |
adelino | 1:a74e42cf52b2 | 115 | |
adelino | 1:a74e42cf52b2 | 116 | }; |
adelino | 1:a74e42cf52b2 | 117 | |
adelino | 1:a74e42cf52b2 | 118 | #endif |