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

40 wiersze
752 B
C++
Czysty Zwykły widok Historia

2021-05-21 16:35:01 +00:00
#include <stdio.h>
#include "pico/stdlib.h"
// Uncomment the below line to switch from the PMW3901 to the PAA5100
//#define USE_PAA5100
#ifndef USE_PAA5100
#include "breakout_pmw3901.hpp"
#else
#include "breakout_paa5100.hpp"
#endif
using namespace pimoroni;
2021-05-21 16:35:01 +00:00
#ifndef USE_PAA5100
typedef BreakoutPMW3901 FlowSensor;
#else
typedef BreakoutPAA5100 FlowSensor;
#endif
2021-05-21 16:35:01 +00:00
FlowSensor flo(BG_SPI_FRONT);
2021-05-21 16:35:01 +00:00
int main() {
stdio_init_all();
flo.init();
flo.set_rotation(FlowSensor::DEGREES_0);
2021-06-15 13:45:05 +00:00
int16_t tx = 0, ty = 0;
2021-05-21 16:35:01 +00:00
int16_t x = 0, y = 0;
while(true) {
2021-06-15 13:45:05 +00: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 16:35:01 +00:00
};
return 0;
}