#include <Adafruit_TSL2561_U.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
 
const int ledPin1 = 32;
const int ledPin2 = 33;
float ir;
float nir;
float full;
float vis;
float NDVI;

Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
 
void configureSensor(void)
{
  tsl.setGain(TSL2561_GAIN_1X);   
  tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS); 
}
void setup()
{
  pinMode (ledPin1, OUTPUT);
  pinMode (ledPin2, OUTPUT);
  configureSensor();
  Serial.begin(9600);
  Wire.begin();
}
 
void loop()
{
  int ms = 500;
delay(ms);
digitalWrite (ledPin1, HIGH); 
digitalWrite (ledPin2, HIGH); 

 uint16_t y = 0;
 uint16_t z = 0;

    tsl.getLuminosity(&y, &z);
    full = y;
    ir=z;
    vis = full - ir;
    nir = ir;
    NDVI = (nir - vis)/(nir + vis);

    Serial.print(nir); Serial.println("  1 (600-1100nm)");
    Serial.print(vis); Serial.println("  1 (Visible)");
    Serial.print(NDVI); Serial.println("  1 (NDVI)");
    Serial.println("");
  
}
