#include "SevSeg.h"
SevSeg sevseg;
// set voltage read pin
int readPin = A3;
// initialize variables
float V2 = 0;
int readVal = 0;
unsigned long previousMillis = 0;
const long interval = 200;
void setup() {
// set the read pin as an input
pinMode(readPin, INPUT);
// start the serial to show results
Serial.begin(9600);
// num of digits on sevseg
byte numDigits = 4;
// defines pins used for the digits in order; DIG1, DIG2, DIG3, DIG4
byte digitPins[] = {8, 9, 10, 11};
// Defines Arduino pin connections in order: A, B, C, D, E, F, G, DP
byte segmentPins[] = {13, 12, 2, 3, 4, 5, 6, 7};
// Initialize sevseg object
sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins);
}
void display() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// Save the last time we blinked the LED
previousMillis = currentMillis;
readVal = analogRead(readPin);
V2 = ((5.0 / 1023.0) * readVal * 10000) * 1.5;
// print V2 in the serial (for testing)
Serial.print(V2 / 10);
Serial.println(" mV");
V2 /= 10; // FOR WOKWI
decPlace = 0; // FOR WOKWI
}
}
void loop() {
display();
if (V2 > 30) {
sevseg.setNumber(V2, 1);
} else {
sevseg.setNumber(0);
}
if (V2 == 0){
sevseg.blank();
} else{
sevseg.refreshDisplay();
}
}