Version 1.0 - Library for Parallax OFN module 27903

Fork of OFN by Neha Kadam

Import library

Public Member Functions

OFN (PinName sda, PinName scl)
Constructor.
bool checkMotion ()
Function to check if motion has been detected Checks the 7th bit of MOTION register and Returns true if motion detected else returns false.
int readX ()
Function to get displacement in the X direction Returns an integer value.
int readY ()
Function to get displacement in the X direction Returns an integer value.
int readOrientation ()
Function to read the Orientation register Returns an integer value 1 - default orientation 0 - rotated by 90 degrees.
Committer:
nkadam
Date:
Mon Mar 09 03:58:38 2015 +0000
Revision:
1:ba28114bd6bb
Parent:
0:c559e09a7b5d
Child:
2:757ad351c8c6
Ver 1.0;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nkadam 0:c559e09a7b5d 1
nkadam 0:c559e09a7b5d 2 #ifndef OFN_H
nkadam 0:c559e09a7b5d 3 #define OFN_H
nkadam 0:c559e09a7b5d 4
nkadam 0:c559e09a7b5d 5 #include "mbed.h"
nkadam 0:c559e09a7b5d 6
nkadam 0:c559e09a7b5d 7 #define DEVICE_ADDR 0x33
nkadam 0:c559e09a7b5d 8 #define PRODUCT_ID_ADDR 0x00
nkadam 0:c559e09a7b5d 9 #define REVISION_ID_ADDR 0x01
nkadam 0:c559e09a7b5d 10
nkadam 0:c559e09a7b5d 11 #define SOFT_RESET 0x3A
nkadam 0:c559e09a7b5d 12 #define OFN_ORIENTATION_CTRL 0x77
nkadam 0:c559e09a7b5d 13
nkadam 0:c559e09a7b5d 14 #define ORIENT_DEFAULT 1
nkadam 0:c559e09a7b5d 15 #define ORIENT_ROTATED_CLKWISE 0
nkadam 0:c559e09a7b5d 16
nkadam 0:c559e09a7b5d 17 class OFN {
nkadam 0:c559e09a7b5d 18
nkadam 0:c559e09a7b5d 19 public:
nkadam 0:c559e09a7b5d 20
nkadam 0:c559e09a7b5d 21 /**
nkadam 0:c559e09a7b5d 22 * Constructor.
nkadam 0:c559e09a7b5d 23 *
nkadam 0:c559e09a7b5d 24 * @param sda mbed pin to use for SDA line of I2C interface.
nkadam 0:c559e09a7b5d 25 * @param scl mbed pin to use for SCL line of I2C interface.
nkadam 0:c559e09a7b5d 26 */
nkadam 0:c559e09a7b5d 27 OFN(PinName sda, PinName scl);
nkadam 0:c559e09a7b5d 28
nkadam 0:c559e09a7b5d 29 /**
nkadam 0:c559e09a7b5d 30 *
nkadam 0:c559e09a7b5d 31 * Function to check if motion has been detected
nkadam 0:c559e09a7b5d 32 * Checks the 7th bit of MOTION register and
nkadam 0:c559e09a7b5d 33 * Returns true if motion detected else returns false
nkadam 0:c559e09a7b5d 34 */
nkadam 0:c559e09a7b5d 35 bool checkMotion();
nkadam 0:c559e09a7b5d 36
nkadam 0:c559e09a7b5d 37 /**
nkadam 0:c559e09a7b5d 38 *
nkadam 0:c559e09a7b5d 39 * Function to get displacement in the X direction
nkadam 0:c559e09a7b5d 40 * Returns an integer value
nkadam 0:c559e09a7b5d 41 */
nkadam 0:c559e09a7b5d 42 int readX();
nkadam 0:c559e09a7b5d 43
nkadam 0:c559e09a7b5d 44 /**
nkadam 0:c559e09a7b5d 45 *
nkadam 0:c559e09a7b5d 46 * Function to get displacement in the X direction
nkadam 0:c559e09a7b5d 47 * Returns an integer value
nkadam 0:c559e09a7b5d 48 */
nkadam 0:c559e09a7b5d 49 int readY();
nkadam 0:c559e09a7b5d 50
nkadam 0:c559e09a7b5d 51 /**
nkadam 0:c559e09a7b5d 52 *
nkadam 0:c559e09a7b5d 53 * Function to read the Orientation register
nkadam 0:c559e09a7b5d 54 * Returns an integer value
nkadam 0:c559e09a7b5d 55 * 1 - default orientation
nkadam 0:c559e09a7b5d 56 * 0 - rotated by 90 degrees
nkadam 0:c559e09a7b5d 57 */
nkadam 0:c559e09a7b5d 58 int readOrientation();
nkadam 0:c559e09a7b5d 59
nkadam 0:c559e09a7b5d 60 private:
nkadam 0:c559e09a7b5d 61
nkadam 0:c559e09a7b5d 62 I2C i2c;
nkadam 0:c559e09a7b5d 63
nkadam 0:c559e09a7b5d 64 char MOTREG_ADDR; // To contain address of Motion Register
nkadam 0:c559e09a7b5d 65 char DELTA_X_ADDR; // To contain address of Delta_X Register
nkadam 0:c559e09a7b5d 66 char DELTA_Y_ADDR; // To contain address of Delta_Y Register
nkadam 0:c559e09a7b5d 67 int MotReg; // To contain value of Motion Register
nkadam 0:c559e09a7b5d 68 bool moved; // To contain value of state of Motion
nkadam 0:c559e09a7b5d 69
nkadam 0:c559e09a7b5d 70 char raw_delta_X[1]; // To contain raw sensor reading of Delta_X
nkadam 0:c559e09a7b5d 71 int delta_X; // To contain correct reading of Delta_X
nkadam 0:c559e09a7b5d 72
nkadam 0:c559e09a7b5d 73 char raw_delta_Y[1]; // To contain raw sensor reading of Delta_Y
nkadam 0:c559e09a7b5d 74 int delta_Y; // To contain correct reading of Delta_Y
nkadam 0:c559e09a7b5d 75 };
nkadam 0:c559e09a7b5d 76
nkadam 0:c559e09a7b5d 77 #endif /* OFN_H */