Guest User

Untitled

a guest
Sep 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <BLEAdvertisedDevice.h>
  2. #include <BLEDevice.h>
  3. #include <BLEScan.h>
  4.  
  5. const int PIN = 2;
  6. const int CUTOFF = -60;
  7.  
  8. void setup() {
  9. pinMode(PIN, OUTPUT);
  10. BLEDevice::init("");
  11. }
  12.  
  13. void loop() {
  14. BLEScan *scan = BLEDevice::getScan();
  15. scan->setActiveScan(true);
  16. BLEScanResults results = scan->start(1);
  17. int best = CUTOFF;
  18. for (int i = 0; i < results.getCount(); i++) {
  19. BLEAdvertisedDevice device = results.getDevice(i);
  20. int rssi = device.getRSSI();
  21. if (rssi > best) {
  22. best = rssi;
  23. }
  24. }
  25. digitalWrite(PIN, best > CUTOFF ? HIGH : LOW);
  26. }
Add Comment
Please, Sign In to add comment