Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. /* Ping))) Sensor
  2.  
  3. This sketch reads a PING))) ultrasonic rangefinder and returns the
  4. distance to the closest object in range. To do this, it sends a pulse
  5. to the sensor to initiate a reading, then listens for a pulse
  6. to return. The length of the returning pulse is proportional to
  7. the distance of the object from the sensor.
  8. */
  9.  
  10. #include <Wire.h>
  11. #include "Adafruit_LEDBackpack.h"
  12. #include "Adafruit_GFX.h"
  13. Adafruit_7segment matrix = Adafruit_7segment();
  14. int triggerPin = 5;
  15. int echoPin = 7;
  16. int declare = 0;
  17. long duration = 0;
  18. float in = 0;
  19.  
  20. void setup() {
  21. Serial.begin(115200);
  22. matrix.begin(0x70);
  23. pinMode (triggerPin, OUTPUT);
  24. pinMode (echoPin, INPUT);
  25. qk
  26. }
  27.  
  28. void loop(){
  29. digitalWrite(triggerPin, LOW);
  30. delayMicroseconds(5);
  31. digitalWrite(triggerPin, HIGH);
  32. delayMicroseconds(5);
  33. digitalWrite(triggerPin, LOW);
  34. delayMicroseconds(5);
  35.  
  36. //Inputs:
  37. duration = pulseIn(echoPin, HIGH);
  38.  
  39.  
  40.  
  41. // Calculations: convert the time into a distance
  42. in = duration /29.0 / 2.0;
  43.  
  44.  
  45.  
  46. //Outputs
  47. Serial.print(in);
  48. Serial.print("in");
  49. Serial.println();
  50.  
  51. matrix.print(in);
  52. matrix.writeDisplay();
  53. delay(400);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement