#include <TM1637Display.h> // 7 segment display

#include <Wire.h>
#include "TM1637.h" // 7 segment display

const int moisturePin = A2; // AUOT on moisture probe
const int clockPin = 3; // TM1637 CLK
const int dataPin = 4;  // TM1637 DIO

const int waterVal = 260;  //submerged probe reading
const int airVal = 571;  // dry probe reading

TM1637 tm1637(clockPin, dataPin);


void setup() {
Serial.begin(9600);

tm1637.init();
tm1637.set(BRIGHT_DARKEST);

delay(500);
}


void loop() {
  int probeVal = analogRead(A2);  // read raw moisture value
  int percent = map(probeVal, airVal, waterVal, 0, 100);  // using probe callibration values to find a percentage out of 100
    percent = constrain(percent, -10, 110);  // percent can be from -10 to 110, gives room for callibration errors

Serial.print("Value = ");  // print raw moisture value in serial monitor
Serial.println(probeVal);  
delay(500);

Serial.print("Moisture = ");  // print moisture percentage in serial monitor
Serial.println(percent);
delay(500);

// digits 
int digit1 = percent / 10;  // assign TM1637 digit 1 to show the first number of the moisture percentage
int digit2 = percent % 10;  // digit 2 = second number of moisture percentage 

// 100% or higher reads as A1 


// display 
  tm1637.display(1, digit1);
  tm1637.display(2, digit2);

  delay(1000);

}

