PSI3422_Aula3

Fork of NunchukLib by decarvalho adelino

Committer:
adelino
Date:
Sun Nov 17 13:35:01 2013 +0000
Revision:
1:72d62147e2b8
Parent:
0:37e9a0644485
Child:
2:0a8f43931041
Library to use the wii nunchuk distributed by Nintendo

Who changed what in which revision?

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