NetBurner 3.5.6
PDF Version
SparkFun_Qwiic_Joystick_Arduino_Library.h
1/*
2 This is a library written for the SparkFun Qwiic Joystick
3 SparkFun sells these at its website: www.sparkfun.com
4 Do you like this library? Help support SparkFun. Buy a board!
5 https://www.sparkfun.com/products/15168
6
7 Written by Nathan Seidle @ SparkFun Electronics, November 25th, 2018
8 Modified by Wes Furuya @ SparkFun Electronics, February 5th, 2019
9
10 The Qwiic Joystick is a I2C controlled analog joystick
11
12 https://github.com/sparkfun/SparkFun_Qwiic_Joystick_Arduino_Library
13
14 Development environment specifics:
15 Arduino IDE 1.8.5
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
24*/
25
26#ifndef _SPARKFUN_QWIIC_JOYSTICK_ARDUINO_LIBRARY_H
27#define _SPARKFUN_QWIIC_JOYSTICK_ARDUINO_LIBRARY_H
28#include "Arduino.h"
29#include "Wire.h"
30
31#define QWIIC_JOYSTICK_ADDR 0x20 //7-bit unshifted default I2C Address
32
33//Map to the various registers on the Joystick
34enum joystickRegisters {
35 JOYSTICK_ID = 0x00,
36 JOYSTICK_VERSION1, // 0x01
37 JOYSTICK_VERSION2, // 0x02
38 JOYSTICK_X_MSB, // 0x03
39 JOYSTICK_X_LSB, // 0x04
40 JOYSTICK_Y_MSB, // 0x05
41 JOYSTICK_Y_LSB, // 0x06
42 JOYSTICK_BUTTON, // 0x07
43 JOYSTICK_STATUS, // 0x08 //1 - button clicked
44 JOYSTICK_I2C_LOCK, // 0x09
45 JOYSTICK_CHANGE_ADDRESS, // 0x0A
46};
47
48class JOYSTICK {
49 public:
50 JOYSTICK();
51
52 boolean begin(TwoWire &wirePort = Wire, uint8_t deviceAddress = QWIIC_JOYSTICK_ADDR);
53 boolean isConnected(); //Checks if sensor ack's the I2C request
54
55 uint16_t getHorizontal(); //Returns the number of indents the user has turned the knob
56 uint16_t getVertical(); //Returns the number of indents the user has turned the knob
57
58 byte getButton(); //Returns true if knob has been twisted
59 byte checkButton(); //Return true if button is currently pressed.
60
61 String getVersion(); //Returns a two byte Major/Minor version number
62
63 boolean setI2CAddress(uint8_t newAddress); //Change the I2C address to newAddress (Prints new address over serial)
64
65 private:
66 TwoWire *_i2cPort;
67 uint8_t _deviceAddress;
68
69 uint8_t readRegister(uint8_t addr);
70
71 boolean writeRegister(uint8_t addr, uint8_t val);
72};
73
74#endif
Wire interface class.
Definition Wire.h:43