I'm trying to create a code to interpret the output of a Vishay receiver. i.e. code that measures the length of a pulse (but I don't want to use PulseIn). I initially wrote a big long code that would interpret it all for me, but I'm having trouble making it go into the interrupt so I reduced my code down to:
void loop()
{
Serial.print("L");
delay(100); //so we're not overwhelmed with values
}
So that all I'm trying to do is get the program to enter the interrupt and print "G" (I know, I know, shouldn't print from an interrupt) at the moment. Does this seem right? It's only printing me a line of Ls, not a G in sight.
I'm testing it with a 2Hz, 5 V peak to peak square wave signal.
Thanks in advance! I've only just started using Arduino.
Claire
Pins 2 & 3 are the hardware interrupt pins, you attach an interrupt to them.
I don't see that happening with your code (but I'm not much into the register stuff either).
What is pin 8 supposed to be doing?
Here's a collection of the bits I used in an RF remote control - push a button, create an interrupt.
//***************************************************
// * Name: pin2Interrupt, "ISR" to run when interrupted in Sleep Mode
void pin2Interrupt()
{
g_flag = 1;
}
void loop(){
If (g_flag == 0){
Serial.print ('L');
}
else {
detachInterrupt(0); //disable interrupts while printing
Serial.print ('G');
g_flag = 0; // reset the interrupt flag
attachInterrupt(0, pin2Interrupt, LOW); // ready for next interrupt
}
}
If you can get that working, then you will see a G on each rising edge.
Next you can change it to have the ISR be
g_flag = 1-g_flag;
and not clear g_flag with the serialprint, but hold it,
and let the state will change in the interrupt 1-0-1-0 with each edge.
Then, add stuff to capture the time when the g_flag changes.