I am trying to test attachinterrupt function on arduino uno. Simple program:
#include <LiquidCrystal_I2C.h>
// Max RPM bargraph value
#define RPM_MAX 8000
#define RPM_RED 5000
#define engineCycles 4
#define engineCylinders 6
const byte pInterrupt = 2;
const byte pLED = 13;
volatile byte bState = LOW;
volatile unsigned int iTicks = 0;
int iReadTime=1000;
long lLastMS=0;
void setup()
{
pinMode(pInterrupt, INPUT_PULLUP);
pinMode(pInterrupt, INPUT);
pinMode(pLED, OUTPUT);
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(pInterrupt), intTick, RISING); //2, ES
}
void loop()
{
digitalWrite(pLED, bState);
iTicksCycle=millis()-lLastMS;
if(iTicksCycle>=iReadTime)
{
lLastMS=millis();
Serial.print(F("Time: "));
Serial.println(iTicksCycle);
Serial.print(F("Ticks: "));
Serial.println(iTicks);
iTicks=0;
}
}
void intTick() //interrupt for gathering tachometer signal
{
++iTicks;
bState = !bState;
}
The signal line on pin #2 comes from another arduino setup to digitalwrite high, delay(500),digitalwrite low.
So I expect pin #13 to match the pattern I see on the other board, except there seems to be some type of extra noise interference. It seems to trigger erratically on it's own, for reasons unknown. IS there something I am not doing that I need to do? To me this seems to be a simply obvious, but I am at my wits end and need help please.