Simple 2 LEDs that change when switched.

Hi again,

I am looking at using a ATTINY85 to control two LEDs with one input switch. Basically, an LED on one pin that is lit when a switch is in the open position, and when the switch is closed the output instantly swaps to the other LED for a minimum of 100ms, switching back when the switch is open again. I will continue looking through the web for answers but it should be simple.

I have already done this in analog form with two transistors but I want to get it all onto as small a circuit as possible.

The other thing would be to get the ATTINY to measure voltage in the circuit and shut down after it drops below 4v. I have seen a post of how it was done but cannot find it again.

The use for this is the camera trap I have been working on, it needs to switch for the minimum of 100ms so even the fastest break in the IR receiver will translate to the camera responding. The two outputs are so that I can have the option for an inverted output. The voltage shut off is so that the receiver does not think the beam is broken and fire the camera when the voltage drop causes the beam to lose range.

Thanks to those that helped me with the 38khz sketch. It is working well. A little too well as the signal is quite powerful, though easily toned down with a variable resistor.

I can't get it to work, I have tried several variations and so far can only get:

  • both LEDs blinking rapidly


  • both on but one turns off when input switches on

I have solved the "brown out" issue by finding an option in the Arduino menu.

Any help getting the LEDs to switch from one to the other cleanly would be great.


This is the code so far:

const int LED1 = 0;
const int LED2 = 1;
const int SW = 2;

 int val=0;

void setup()
  pinMode(SW, INPUT);

 void loop()