Last active
April 3, 2022 21:23
-
-
Save slashinfty/87855e54e7560dba5df3ce502ab5e212 to your computer and use it in GitHub Desktop.
Voltmeter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Grove_4Digital_Display library | |
#include <TM1637.h> | |
int VREAD = 0; | |
int CLK = 8; | |
int DIO = 7; | |
float vout = 0.0; | |
float vin = 0.0; | |
float R1 = 100000.0; | |
float R2 = 10000.0; | |
int val = 0; | |
TM1637 TM(CLK, DIO); | |
void setup() { | |
pinMode(VREAD, INPUT); | |
TM.init(); | |
TM.set(2); | |
TM.clearDisplay(); | |
TM.point(1); | |
TM.display(0, 0); | |
TM.display(1, 0); | |
TM.display(2, 0); | |
TM.display(3, 0); | |
} | |
void loop() { | |
val = analogRead(VREAD); | |
vout = (val * 5.0) / 1024.0; | |
float curr = vout / (R2 / (R1 + R2)); | |
if (curr < 0.09) { | |
curr = 0.0; | |
} | |
if (curr != vin) { | |
vin = curr; | |
int whole = vin; | |
int dec = vin * 100 - (whole * 100); | |
TM.clearDisplay(); | |
TM.point(1); | |
TM.display(0, whole / 10); | |
TM.display(1, whole % 10); | |
TM.display(2, dec / 10); | |
TM.display(3, dec % 10); | |
} | |
delay(500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment