Building a Nunchuk Class
The interface of our Nunchuk class (and the main part of its implementation) looks as follows:
Tinkering/NunchukDemo/nunchuk.h | |
Line 1 | #ifndef __NUNCHUK_H__ |
- | #define __NUNCHUK_H__ |
- | #define NUNCHUK_BUFFER_SIZE 6 |
- | |
5 | class Nunchuk { |
- | public: |
- | void initialize(); |
- | bool update(); |
- | |
10 | int joystick_x() const { return _buffer[0]; } |
- | int joystick_y() const { return _buffer[1]; } |
- | |
- | int x_acceleration() const { |
- | return ((int)(_buffer[2]) << 2) | ((_buffer[5] >> 2) & 0x03); |
15 | } |
- | |
- | int y_acceleration() const { |
- | return ((int)(_buffer[3]) << 2) | ((_buffer[5] >> 4) & 0x03); |
- | } |
20 | |
- | int z_acceleration() const { |
- | return ((int)(_buffer[4]) << 2) | ((_buffer[5] ... |
Get Arduino: A Quick-Start Guide, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.