Commit 41b01b5e authored by gujames's avatar gujames
Browse files

testing one US, still need calibration equation

parent 9005cf80
const int trig_pin_mid = 11;
const int echo_pin_mid= 10;
const int trig_pin_light = 2;
struct Ultrasoundreads {
long data1, data2, data3;
} ultrasound;
Ultrasoundreads data[20];
int index = 0;
void setup() {
// put your setup code here, to run once:
// add reading of specific pins
pinMode(trig_pin_mid, OUTPUT);
pinMode(echo_pin_mid, INPUT);
// output a light signal when close by
pinMode(trig_pin_light, OUTPUT);
Serial.begin(9600); // Starts the serial communication
//read data from one US sensor
long read_pin(int trig_pin, int echo_pin, int start_microseconds, int end_microseconds) {
digitalWrite(trig_pin, LOW);
digitalWrite(trig_pin, HIGH);
digitalWrite(trig_pin, LOW);
return pulseIn(echo_pin, HIGH);
long calculate_distance(long duration) {
return duration / 58.2;
void loop() {
long duration_mid = read_pin(trig_pin_mid, echo_pin_mid, 2, 10);
long distance = calculate_distance(duration_mid);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment