pimoroni-pico/examples/breakout_pmw3901/motion/motion.cpp

35 lines
679 B
C++
Raw Normal View History

2021-05-21 17:35:01 +01:00
#include <stdio.h>
#include "pico/stdlib.h"
using namespace pimoroni;
// Pick *one* sensor type by uncommenting the relevant lines below:
// PMW3901
2021-05-21 17:35:01 +01:00
#include "breakout_pmw3901.hpp"
typedef BreakoutPMW3901 FlowSensor;
2021-05-21 17:35:01 +01:00
// PAA5100
//include "breakout_paa5100.hpp"
//typedef BreakoutPAA5100 FlowSensor;
2021-05-21 17:35:01 +01:00
FlowSensor flo(BG_SPI_FRONT);
2021-05-21 17:35:01 +01:00
int main() {
stdio_init_all();
flo.init();
flo.set_rotation(FlowSensor::DEGREES_0);
2021-06-15 14:45:05 +01:00
int16_t tx = 0, ty = 0;
2021-05-21 17:35:01 +01:00
int16_t x = 0, y = 0;
while(true) {
2021-06-15 14:45:05 +01:00
if(flo.get_motion(x, y)) {
tx += x;
ty += y;
printf("Relative: x %6d, y %6d | Absolute: tx %6d, ty %6d\n", x, y, tx, ty);
}
sleep_ms(10);
2021-05-21 17:35:01 +01:00
};
return 0;
}