#include "Adafruit_VL53L0X.h"

Adafruit_VL53L0X lox = Adafruit_VL53L0X();
int buzzer_pin = 8;  // What pin is the buzzer connected to
int i = 0;

void setup() {
  Serial.begin(115200);
  pinMode(buzzer_pin, OUTPUT);  // Configure the buzzer pin as an output pin
  // wait until serial port opens for native USB devices
  while (!Serial) {
    delay(1);
  }

  Serial.println("Adafruit VL53L0X test");
  if (!lox.begin()) {
    Serial.println(F("Failed to boot VL53L0X"));
    while (1)
      ;
  }
  // power
  Serial.println(F("VL53L0X API Simple Ranging example\n\n"));
}


void loop() {
  VL53L0X_RangingMeasurementData_t measure;

  lox.rangingTest(&measure, false);  // pass in 'true' to get debug data printout!
Serial.println(measure.RangeMilliMeter);

  if (measure.RangeMilliMeter <= 300) {
    tone(buzzer_pin, 2000); // Create a tone/note from 500 to 2400 Hz
		delay(20);
  } else if (measure.RangeMilliMeter > 300 && measure.RangeMilliMeter <= 500) {
   tone(buzzer_pin, 50); // Create a tone/note from 500 to 2400 Hz
		delay(20);
  } else {
    noTone(8); // Create a tone/note from 500 to 2400 Hz
		delay(20);

  }
}


/*
 for(i = 25; i < 120; i++)
	{
		tone(buzzer_pin, 200); // Create a tone/note from 500 to 2400 Hz
		delay(20);
	
  }
}
tone(buzzer_pin, 400); // Create a tone/note from 500 to 2400 Hz
		delay(20);

    */