#include <Wire.h>
#include "TM1637.h"

const int CLK = 6;
const int DIO = 7;
TM1637 tm1637(CLK,DIO);

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int buttonPin = A2;     // the number of the pushbutton pin
int sensorValue = 0;        // value read from the pot
int buttonState = 0;         // variable for reading the pushbutton status


void setup()
{
  Serial.begin(9600);
    
  tm1637.init();
  tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
  
  pinMode(analogInPin, INPUT);
  pinMode(buttonPin, INPUT);

}

void loop()
{

  // sensorValue = analogRead(analogInPin);   // read the analog in value:
  buttonState = digitalRead(buttonPin);   // read the state of the button value:

  float val=sensorValue*(3.30/1024.0);   

  if (buttonState == HIGH) {

  sensorValue = analogRead(analogInPin);   // read the analog in value:
  
  // print the results to the Serial Monitor:
  Serial.print("Analog Sensor Output = ");
  Serial.print(sensorValue);
  Serial.print("\n"); 

// print the results to the Serial Monitor:
  Serial.print("Voltage = ");
  Serial.print(val);
  Serial.print(" V");
  Serial.print("\n");

  tm1637.displayNum(sensorValue);  
  delay(500);
  tm1637.clearDisplay();
  
  } 
  
  else {
  sensorValue = digitalRead(analogInPin);   // read the state of the pushbutton value:
  
  // print the results to the Serial Monitor:
  Serial.print("Digital Sensor Output = ");
  Serial.print(sensorValue);
  Serial.print("\n"); 
  
// print the results to the Serial Monitor:
  Serial.print("Voltage = ");
  Serial.print(val);
  Serial.print(" V");
  Serial.print("\n");
      
  tm1637.displayNum(sensorValue);  
  delay(500);
  tm1637.clearDisplay();

  }


}
