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
PMW3901/PMW3901.h
- Committer:
- fbob
- Date:
- 2018-05-08
- Revision:
- 6:c7bc001826ba
- Parent:
- 5:1ef8b91a0318
- Child:
- 7:56608cce81ee
File content as of revision 6:c7bc001826ba:
#ifndef PMW3901_h #define PMW3901_h #include "mbed.h" // #define PRODUCT_ID 0x00 // #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" * * // Declare serial object * USBSerial pc; * // Declare sensor object with correpondent SPI pins (miso, mosi, sclk, csel) * PMW3901 flow(PA_7,PA_6,PA_5,PB_4); * * // Main program * int main() * { * // Initialize sensor * flow.init(); * // Infinite loop * while(1); * { * // Read data from sensor * flow.read(); * // Print data from sensor * pc.printf("Optical flow []: %6.2f %6.2f \n\n", flow.x, flow.y); * // Wait 0.5 seconds * wait(0.5); * } * } * @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 */ bool init(); /** **/ void read(); /** Optical flow data in x-axis (px) **/ float x; /** Optical flow data in y-axis (px) **/ float y; private: /** SPI bus */ SPI spi; /** Chip select */ DigitalOut cs; /** **/ void setup_spi(); /** **/ bool test_spi(); /** **/ void setup_flow(); /** **/ void read_flow(); }; #endif