    7  miso  12
 */
 
-/*
-   17  / int 0    ---> record value to influxdb
-   16 / 15 ---> detect range ( m / u / n )
-*/
-
-/* 250 report / sec
-Adafruit_ADS1015.h
---> #define ADS1115_CONVERSIONDELAY         (1)
-
-Adafruit_ADS1015.cpp
----> int16_t Adafruit_ADS1015::readADC_Differential_0_1() {
-  // Start with default values
-  uint16_t config = ADS1015_REG_CONFIG_CQUE_NONE    | // Disable the comparator (default val)
-                    ADS1015_REG_CONFIG_CLAT_NONLAT  | // Non-latching (default val)
-                    ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low   (default val)
-                    ADS1015_REG_CONFIG_CMODE_TRAD   | // Traditional comparator (default val)
-                    ADS1015_REG_CONFIG_DR_3300SPS   | // 1600 samples per second (default)
-                    ADS1015_REG_CONFIG_MODE_SINGLE;   // Single-shot mode (default)
-
-
- */
-
 #include <avr/wdt.h>
 #include <avr/interrupt.h>
 #include <avr/sleep.h>
 #include <avr/pgmspace.h>
 #include <avr/power.h>
 #include <SPI.h>
-#include <LowPower.h>
 #include "nRF24L01.h"
 #include "RF24.h"
 #include <Wire.h>
-//#include "PinChangeInterrupt.h"
 #include <Adafruit_ADS1015.h>
 
 #define adc_disable() (ADCSRA &= ~(1<<ADEN)) // disable ADC

RF24 radio(CE_PIN, CSN_PIN);
Adafruit_ADS1115 ads(0x48);

// analogPin 3 / 2 / 1 / int 0
const int wakeupPin = 2;
const int recordPin = 17;
const int nanoPin   = 16;
const int microPin  = 15;
const int ledPin    = 14;

int rangeStatus;
volatile unsigned long counterForloop;
volatile unsigned long counterForloop_old;
volatile boolean checkRangenow;
volatile int noOfWake;

void checkRange() {
  checkRangenow = true;
}

void wakeUp() {
  noOfWake++;
  counterForloop_old = counterForloop;
  checkRangenow = true;
  //detachInterrupt(digitalPinToInterrupt(2));
  radio.powerUp();
  checkRecordBttn();
}

void sleepNow() {
  radio.powerDown();
  digitalWrite(ledPin, LOW);
  attachInterrupt(digitalPinToInterrupt(2), wakeUp, FALLING);
  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
}

void checkRecordBttn() {
  attachInterrupt(digitalPinToInterrupt(2), sleepNow, FALLING);
}

void setup() {
  //Serial.begin(115200);

  delay(20);
  adc_disable();

  pinMode(recordPin, INPUT_PULLUP);
  pinMode(wakeupPin, INPUT_PULLUP);
  pinMode(microPin, INPUT_PULLUP);
  pinMode(nanoPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);

  int microStatus = digitalRead(microPin);
  int nanoStatus  = digitalRead(nanoPin);

    }
    delay(100);
  }
  attachInterrupt(digitalPinToInterrupt(3), record, RISING);
}

void loop() {
  if (dorecored == true) {
    digitalWrite(ledPin, HIGH);
    int microStatus = digitalRead(microPin);
    int nanoStatus  = digitalRead(nanoPin);

    rangeStatus = microStatus << 1;
    rangeStatus = rangeStatus + nanoStatus;

    int16_t results;
    float multiplier = 0.125F;
    //results = ads.readADC_Differential_0_1();
    results = ads.getLastConversionResults_no_delay();

    payload.data1 = results * multiplier ;
    payload.data2 = rangeStatus;

    payload._salt = recordNo ;
    payload.volt = 3300;

    ads.readADC_Differential_0_1_no_delay();
    
    radio.write(&payload , sizeof(payload));
    
    digitalWrite(ledPin, LOW);
  } else {
    digitalWrite(ledPin, LOW);
  }
}
