I’m trying to do something clever. Actually, I’ve done it in Arduino, just not in electron.
I want a varying pulsewidth output, so I used analogWrite to put out a pulse. But every 8 pulses, I want to change the width, so I figured on attaching an interrupt to detect when the pin goes low so the interrupt handler can analogWrite a different pulse width.
Using an electron, I think A5 is the only pin that can both trigger an interrupt and analogWrite.
So I set A5 to be output:
pinMode( A5, OUTPUT );
And attached an interrupt:
attachInterrupt( A5, IntHandler, FALLING);
The interrupt is:
uint32_t icount = 0 ;
void IntHandler()
{
icount += 1 ;
}
Attach the interrupt:
analogWrite(A5, 128, 440);
My oscilloscope shows pulses coming out a A5, but my icount doesn’t increment. Do I have to mark icount as “volatile” like in an AVR? I have SYSTEM_THREAD(ENABLED); so maybe interrupts are disabled? Hmm. Compiler accepts volatile on the icount, but it still doesn’t increment.