Skip to content

Instantly share code, notes, and snippets.

@berkedel
Created October 17, 2015 08:58
Show Gist options
  • Save berkedel/71d2421cfb0d09967caa to your computer and use it in GitHub Desktop.
Save berkedel/71d2421cfb0d09967caa to your computer and use it in GitHub Desktop.
/**
* Add -lupm-ldt0028 flag
*/
#include <iostream>
#include <iomanip>
#include <cmath>
#include <mraa.hpp>
#include <upm/ldt0028.h>
using namespace std;
const int NUMBER_OF_SECONDS = 10;
const int MICROSECONDS_PER_SECOND = 1000000;
const int SAMPLES_PER_SECOND = 50;
const int THRESHOLD = 100;
int main() {
// Create the LDT0-028 Piezo Vibration Sensor object using AIO pin 0
upm::LDT0028* sensor = new upm::LDT0028(1);
mraa::Gpio* led = new mraa::Gpio(13, true, false);
led->write(0);
uint16_t buffer;
for (;;) {
buffer = (uint16_t)sensor->getSample();
if (buffer > 100) {
led->write(1);
printf("SIT\n");
}
else {
led->write(0);
}
usleep(MICROSECONDS_PER_SECOND / SAMPLES_PER_SECOND);
}
// Delete the sensor object
delete sensor;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment