Library containing Crazyflie 2.0 sensors drivers: - LPS25H (barometer) - MPU9250 (IMU) - PMW3901 (optical flow) - VL53L0X (range)
Dependents: Drones-Controlador controladoatitude_cteste Drone_Controlador_Atitude optical_test
Diff: PMW3901/PMW3901.h
- Revision:
- 5:1ef8b91a0318
- Child:
- 6:c7bc001826ba
diff -r d55264b2cad5 -r 1ef8b91a0318 PMW3901/PMW3901.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PMW3901/PMW3901.h Fri May 04 23:03:00 2018 +0000 @@ -0,0 +1,64 @@ +#ifndef PMW3901_h +#define PMW3901_h + +#include "mbed.h" + +#define MOTION 0x02 +// Accelerometer output register addresses +#define DELTA_X_L 0x03 +#define DELTA_X_H 0x04 +#define DELTA_Y_L 0x05 +#define DELTA_Y_H 0x06 + +/** PMW3901 (optical flow sensor) class + * + * Example code (print optical flow data on serial port every 1 second): + * @code + * #include "mbed.h" + * #include "USBSerial.h" + * #include "PMW3901.h" + * + * USBSerial pc; + * PMW3901 flow(PA_7,PA_6,PA_5,PB_4); + * + * int main() + * { + * flow.init(); + * while(1); + * { + * flow.read(); + pc.printf("Optical flow []: %d %d \n\n", flow.x, flow.y); + * wait(1); + * } + * } + * @endcode + * (Need to target to NUCLEO-F401RE board platform) + */ +class PMW3901 +{ + public: + /** Class constructor */ + PMW3901(PinName mosi, PinName miso, PinName sclk, PinName csel); + + /** Initialize optical flow */ + int init(); + /** **/ + void read(); + + /** Optical flow data in x-axis **/ + int16_t x; + /** Optical flow data in y-axis **/ + int16_t y; + private: + /** SPI bus */ + SPI spi; + /** Chip select */ + DigitalOut cs; + + /** **/ + void setup_flow(); + /** **/ + void read_flow(); +}; + +#endif \ No newline at end of file