Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Ping))) Sensor
- This sketch reads a PING))) ultrasonic rangefinder and returns the
- distance to the closest object in range. To do this, it sends a pulse
- to the sensor to initiate a reading, then listens for a pulse
- to return. The length of the returning pulse is proportional to
- the distance of the object from the sensor.
- */
- #include <Wire.h>
- #include "Adafruit_LEDBackpack.h"
- #include "Adafruit_GFX.h"
- Adafruit_7segment matrix = Adafruit_7segment();
- int triggerPin = 5;
- int echoPin = 7;
- int declare = 0;
- long duration = 0;
- float in = 0;
- void setup() {
- Serial.begin(115200);
- matrix.begin(0x70);
- pinMode (triggerPin, OUTPUT);
- pinMode (echoPin, INPUT);
- qk
- }
- void loop(){
- digitalWrite(triggerPin, LOW);
- delayMicroseconds(5);
- digitalWrite(triggerPin, HIGH);
- delayMicroseconds(5);
- digitalWrite(triggerPin, LOW);
- delayMicroseconds(5);
- //Inputs:
- duration = pulseIn(echoPin, HIGH);
- // Calculations: convert the time into a distance
- in = duration /29.0 / 2.0;
- //Outputs
- Serial.print(in);
- Serial.print("in");
- Serial.println();
- matrix.print(in);
- matrix.writeDisplay();
- delay(400);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement