#include "Adafruit_VL53L0X.h"
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


Adafruit_VL53L0X lox = Adafruit_VL53L0X();


RF24 radio(1, 0);  // CE, CSN
const byte address[6] = "00001"; //Note the receiver and transmitter should have the same address.

struct Data_Package {
  uint16_t deviceno = 0;   //Make sure the device no is different for each transmitter.
  uint16_t distance = 0;
  float pitch = 0;
  /*float ax = 0;
  float ay = 0;
  float az = 0;
  float asqrt = 0; */
};



Data_Package data;


void setup() {
  //Serial.begin(9600); 
  //while(!Serial);
  if (!radio.begin()) {
   //Serial.println(F("radio hardware is not responding!!"));
   while (1) {} // hold in infinite loop
  }
  radio.openWritingPipe(address);  //set the address
  radio.setPALevel(RF24_PA_MAX);
  radio.stopListening();  //Set module as transmitter  delay(1000);

  
  if (!lox.begin()) {
    //Serial.println(F("Failed to boot VL53L0X"));
    while(1);
  }


  // start continuous ranging
  lox.startRangeContinuous();

}




void loop() {
  data.deviceno = 1;
  data.distance = lox.readRange();   
  radio.write(&data, sizeof(Data_Package));  //Send the data to the receiver.
  //Serial.println(data.distance);
}
