Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include "ObjectDetection.h"
  2. #include "TINAH.h"
  3. #include "Adafruit_VL53L0X.h"
  4.  
  5.  
  6. constexpr int SHUTDOWNLeft = 0;
  7. constexpr int SHUTDOWNRight = 1;
  8.  
  9. constexpr int shutdown1 = 1;
  10. constexpr int shutdown2 = 2;
  11.  
  12.  
  13.  
  14.  
  15. ObjectDetection::ObjectDetection() {
  16.  
  17. }
  18.  
  19.  
  20.  
  21. boolean ObjectDetection::objectDetect(int courseState) {
  22. Adafruit_VL53L0X lox = Adafruit_VL53L0X();
  23. if (!lox.begin()) {
  24. Serial.println(F("Failed to boot VL53L0X"));
  25. while(1);
  26. }
  27.  
  28. switch (courseState) {
  29. case 1:
  30. analogWrite(SHUTDOWNRight, HIGH);
  31. analogWrite(SHUTDOWNLeft, LOW);
  32. break;
  33. case 2:
  34. analogWrite(SHUTDOWNRight, LOW);
  35. analogWrite(SHUTDOWNLeft, HIGH);
  36. break;
  37. }
  38.  
  39. VL53L0X_RangingMeasurementData_t measure;
  40.  
  41. Serial.print("Reading a measurement... ");
  42. lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!
  43.  
  44. if (measure.RangeStatus != 4) { // phase failures have incorrect data
  45. Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
  46. if(measure.RangeMilliMeter<120){
  47. Serial.print("EWOOOOKKKK");
  48. return true;
  49. }
  50. } else {
  51. Serial.println(" out of range ");
  52. return false;
  53. }
  54.  
  55.  
  56.  
  57.  
  58. return false;
  59. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement