Here's the code to try it if you want @TomGeorge . Thanks for the kudos I am still new to the game. Is there a way to edit the original post to include the code there?
/*
Author: ado88
Email: arduino.ado88@gmail.com
Date: Sept 10, 2021
Revision: Version 0.2.0 Beta
License: CC0 1.0 Universal License
Project: Arduino UNO #1
Remember, "*" means to multiply, "/" means to divide
To convert analog voltage input on A0 to analog output -> 255/513 * voltage or 0.49708 * voltage. I used 513 instead of 512 to avoid
a rounding error at voltage 513 and 514, which caused unexpected behavior from the light. This is a result of debugging, because half
of 1023 is 511.5, which rounds to 512.
255 is max Pulse Width Modulation, 512 is perfect voltage. It equates to 2.5 volts, or equal ratios of resistance in the pot.
It still indicates 512 as perfect. However, it looks green from about 507 to 517 or so, or 2.48v to 2.53v.
NOTE: It is more complicated to use a number other than 512 as perfect, since it creates two ratios that must be used. Try it!
*/
#define BAD 9 // Set red output - may need to switch LED or numbering within program
#define GOOD 10 // Set green output - #define does not use up memory resources on the Uno
#define V_STATUS 0 // Set voltage input pin (A0)
void setup() {
pinMode(BAD, OUTPUT); //Set as outputs for LEDs
pinMode(GOOD, OUTPUT);
analogWrite(GOOD, LOW); // Initializes red/green LED to off (LOW) (0)
analogWrite(BAD, LOW);
}
void loop() {
int voltage = analogRead(V_STATUS);
int pwmOut = 0.49708 * voltage; //int is a whole number variable type so it will automatically round to a whole number
// Also resets pwmOut every time
if (voltage <= 512) { // 512 is seen here as the ideal voltage (2.5V) when using the 5V out pin
analogWrite(GOOD, pwmOut);
analogWrite(BAD, (255 - pwmOut)); // From 0 to 512 its easy to convert the linear change
}
else {
pwmOut = pwmOut - 255; // This adjusts pwmOut, since above 513 voltage, pwmOut is greater than 255
analogWrite(GOOD, (255 - pwmOut)); // 513 to 1023, it is a inverse relationship between increasing voltage and PWM
analogWrite(BAD, pwmOut);
}
delay(3); // delay to view LED change
}