INA219 Power Meter with low voltage flashing LED

Hello, very very new to this. I have a project that I am playing around with. The goal is to have volts/amps/watts/Ah displayed on a .96 OLED 128 x 64. I have the power meter working correctly using Pro_Trinket_Power_Meter Arduino sketch with some adjustments. It will display V and A on one page, wait 2000ms, then display Mw and Ah on a continuous loop.

When I add…

if(loadvoltage<=16.5 && loadvoltage>16.0) {digitalWrite(LED_BUILTIN, HIGH);
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(500);
}
else digitalWrite(LED_BUILTIN, LOW);
}

…it will flash the built in LED at specified voltage range, but messes up the display page delay and the mW/Ah calculations.

Hardware: Adafruit Metro 328
INA219
.96 OLED 132 x 64

Attached is the sketch I am using that will illuminte the LED at specified voltage range and everything is correct. Can I please get some guidance to make the built in LED flash in 1000ms intervals between 16.5 and 16.0 volts? Any help would be greatly appreciated, and again…I have no idea what I am doing. Thanks!

Solid_Power_Meter_v1.2_LED_.ino (3.72 KB)

Look at the Blink WItout Delay example in the IDE. (File->examples-02.Digital->Blink Without Delay) It will show you how to can track elapsed time without using delay() since that function blocks any other code from executing until it is done.

I attached the modified sketch. If loadvoltage is between 16.0 and 16.5, the builtin led should blink (1 sec. ON and 1 sec. OFF).

PS: not tested, check if it works.

Solid_Power_Meter_v1.2_LED_.ino (3.95 KB)

blh64:
Look at the Blink WItout Delay example in the IDE. (File->examples-02.Digital->Blink Without Delay) It will show you how to can track elapsed time without using delay() since that function blocks any other code from executing until it is done.

Thank you blh64, I wil practice with that example.

vlc0617:
I attached the modified sketch. If loadvoltage is between 16.0 and 16.5, the builtin led should blink (1 sec. ON and 1 sec. OFF).

PS: not tested, check if it works.

Thank you vlc0617. That works great and I appreciate you taking the time to fix it for me. I am going to do my best to dissect it and understand it. I was able to program an RGB LED to turn on/off/blink with relation to voltage. Again, thank you.