Hi everyone, I'm attempting to make an LED begin blinking when the voltage from a LiPo hits a certain amount using an Attiny85. I've set it up through the following code - rather than having a hard and fast 'at this voltage we start blinking' rule, since over many monitoring's of the battery discharging it was clear that the only way to have a semi reliable metric would be for consecutive readings to be under 3.2V.
#include <avr/io.h>
int voltageCounter;
int analogData;
bool on;
int analogIn = A3;
int digitalOut = PB1;
void setup() {
pinMode(analogIn, INPUT);
pinMode(digitalOut, OUTPUT);
voltageCounter = 0;
on = false;
digitalWrite(digitalOut, HIGH);
}
void loop() {
analogData = analogRead(analogIn); //store data in analogData variable
if (analogData < 3.2){
if(voltageCounter = 20){
if(on){
digitalWrite(digitalOut, LOW);
on = false;
}
else{
digitalWrite(digitalOut, HIGH);
on = true;
}
}
else{
voltageCounter++;
}
}
else{
voltageCounter = 0;
}
delay(1000); //delay 1 second
}
Connected - (VCC to 5V, LiPo output to A3, GND to GND, PB1 to positive LED leg, and negative LED leg to GND).
The LED comes on, and I've tested all the connections, but the LED does not blink at any point - I'm guessing my issue is most likely with my access of the ATtiny85s pins in the code, but I'm not sure how else to go about it.