I have been playing with interrupts, learning a lot from the forum and from Nick Gammon's site.
I came across some odd behaviour in a piece of code that wrote to a pin when a button was pushed. In Nick's code, he wrote to pin 9 and had an LED wired to that pin. The UNO has an LED on pin 13, so I changed the variable to use that.
I've recast the code to delete all the interrupt code, and stopped the loop after the last pinMode change so the behaviour is the same.
const byte LED = 13;
void setup ()
{
pinMode(Button, INPUT_PULLUP);
} // end of setup
void loop ()
{
pinMode (LED, OUTPUT);
digitalWrite (LED, HIGH);
delay (500);
digitalWrite (LED, LOW);
delay (500);
pinMode (LED, INPUT); // Oddly turns LED on. Pin reads high
while(1);
}
The LED is toggled on and off when the loop runs as expected. But when the pin has its mode changed to INPUT, the LED turns on.
As the pin is configured as an input, I tested by using a jumper to pull pin 13 to 0V, and the LED turned off. Note that the pin is not configured to be INPUT_PULLUP, and that the line before it has it's mode changed writes a LOW to it, so I'd expect it to be at 0V or at least floating.
If I comment out the line that changes the mode, the pin measures 0V and the LED is off.
It's no problem for me, just unexpected.
I have not been able to find a direct connection between the LED or it's bias resistor and pin 13, so there is probably a mosfet in there somewhere.
Can anyone explain what is going on or suggest what I might do next to find out?

