I found some 2mm bicolor LED to use and whipped up this code that works on ATTiny85 (could use 13 if you have one!)
Code: Select all
void setup() {
pinMode(0, INPUT); // charging check, pin 5 of ATTiny85
pinMode(1, INPUT); // done check, pin 6 of ATTiny85
pinMode(2, INPUT); // low battery check pin 7 of ATTiny85
pinMode(3, OUTPUT); // red LED, pin 2 of ATTiny85
pinMode(4, OUTPUT); // green LED, pin 3 of ATTiny85 both on should produce orange/yellow light
} // pin 1 is reset, pin 4 and 8 is GND and VCC
// LEDs are common anode, red and green through current limiting resistor to ATTiny85
void loop() {
if (digitalRead(2) == LOW) { // low battery signal, turn on red only
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
} else if (digitalRead(1) == LOW) { // charging is done status, turn on green only
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
} else if (digitalRead(0) == LOW) { // charging in progress, turn on both LEDs
digitalWrite(3, !digitalRead(3)); // fake PWM, was too orange/red as is
digitalWrite(4, LOW);
} else { // LED off, not plugged in and not powered on.
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
}
When I did the original code, the red/green combined appeared reddish-orange and somewhat hard to see from pure red so I faked PWM on red lead to reduce its brightness by half, it appears more orange/yellow and easier to see. I don't have a datasheet on this specific LED, it is an old stock as no one regularly makes 2mm bicolor LEDs so I don't know if red and green has close spec or if green has slightly higher requirement than red. I supposed I could change the resistor to something a bit lower for green or higher for red.
I coded the priority using if / else so if I am charging and the battery was low, it wouldn't try to flip-flop between low and charging. If it's low, it lights up red and skips the rest of if statements. And when the battery's not low and not charging, the LED stays off.
Total code (with unnecessary options like bootloader, milis(), and brownout all disabled, LTO enabled) was 478 bytes.