Hi,
I have wrote a simple program that tests external interrupts.
tx is connected to the gate of a mosfet and pin2 is the input of a square wave that goes up and down twice on each loop.
Here is the code:
int tx = 12;
volatile int x = 0;
void setup()
{
Serial.begin(9600);
pinMode(tx, OUTPUT);
attachInterrupt(0, increment, RISING);
}
void loop()
{
digitalWrite(tx, HIGH);
delay(10);
digitalWrite(tx, LOW);
Serial.println(x, DEC);
delay(1000);
}
void increment()
{
x++;
}
When i dont turn my circuits battery on, the output is:
1
2
3
4
5
6
7.....
When it is on it is
1
345
346
600
623
689
1100...
Why am i getting such weirdness?
Surely when my external battery off and the external circut recieves no power, the input pin (2) should always be low and the output should be:
0
0
0
0
0
0
when it is on it should be
2
4
6
8
10...
I am totally confused by this.
Any tips or suggestions would be appreciated.
Thanks