Open NicoHood opened 10 years ago
Thanks for the bug reports. I haven't compiled the Example against a Mega, so I never saw the 104-106 error.
And yeah, I screwed up on the pins for the Uno... fixed.
Making the #define NO_PORTB_PINCHANGES is done like this:
The user of the library will put that code in their sketch. Following the
Thus the code inside the PinChangeInt library will recognize the definition, and act on it based on an #ifdef directive ("If this is defined...") or an #ifndef directive ("If this is not defined..."). For example,
ISR(PORTBVECT) { PCintPort::s_PORT='B'; PCintPort::curr = portB.portInputReg; portB.PCint(); }
...This means, that only if PORTB_PINCHANGES is defined, will the code will get compiled. That's all you need to do to have a #define control the compilation of your library.
The C++ in the PinChangeInt library does not make it fat. You'd be surprised at how little the compiler actually turns into machine code. If it's not used, it's generally not compiled. There is a class in the library, but that's little more than a C structure, which is little more than a bundle of assembly language storage locations. Any general-purpose library will be fatter than streamlined, hand coded code but I daresay there's not a lot of fat in the library for what it does... remember, if it's not used, it's not compiled.
But in return for that fat, you get the programming time savings that a library brings you. You don't have to do all the clumsy bit calculations that are necessary to determine if the pin you're interested in is the one that triggered the interrupt... but you'll have to decide if you need to go faster than, say, 30 microseconds or what have you that the interrupt takes, and if you're using up so much of the Arduino's code that the size of the library is too onerous for you.
Thanks for the pointer to the discussion... it really got me thinking. I think the library is complicated, because PinChangeInterrupts are complicated, but it doesn't have to present such a complicated view to the beginner. I think I can clean that up.
Your code is a good example of what I'm talking about: You have one pin and you want to know if it changed.It's perfect for what you want to do, and you have no need for the PinChangeInt library. The library will enable you to have any number of pins and any number of state changes: Any combination of pins can be set to trigger on HI, LOW, or CHANGE.
On Sat, Nov 15, 2014 at 3:55 PM, Nico notifications@github.com wrote:
I noticed some general compiling issues:
PinChangeIntExample: line 104-106 you need to remove the "{" line 57-59 doesnt work for an Uno. A uno doesnt have these pins.
Might be in different examples as well, haven't checked this.
And i've some general questions: How did you made the definition like #define NO_PORTB_PINCHANGES usable in your .h file? What do i have to include to get this feature too?
I am developing an Infrared library which also uses PCINTs. I was searching through the web and only found this library. But the c++ made it very fat. It might be powerful but not for my needs maybe. This lib is powerful, but very hard to understand for beginners. And if you are an expert, you probably dont need this library. Maybe you want to join this discussion (if you havent already)
If you have any suggestions how to probably improve this, let me know. Thx. https://github.com/NicoHood/IRLremote/blob/master/examples/Advanced/Receive_PinChangeInterrupt_Basic/Receive_PinChangeInterrupt_Basic.ino
~NicoHood
— Reply to this email directly or view it on GitHub https://github.com/GreyGnome/PinChangeInt/issues/1.
-Mike Schwager
Wanna have a look at my new PCINT library which is even more compact than normal interrupts? https://github.com/NicoHood/PinChangeInterrupt
One thing i'd like to know is, how i can inline the whole ISR in the .h file. That didnt wok for me with 1.5.8. Any suggestions? Also i still need to rename the cpp to c (not really needed, but its not c++ used) but then the weak function wont compile the properly. It would be nice if you could have a look. :)
I noticed some general compiling issues:
PinChangeIntExample: line 104-106 you need to remove the "{" line 57-59 doesnt work for an Uno. A uno doesnt have these pins.
Might be in different examples as well, haven't checked this.
And i've some general questions: How did you made the definition like #define NO_PORTB_PINCHANGES usable in your .h file? What do i have to include to get this feature too?
I am developing an Infrared library which also uses PCINTs. I was searching through the web and only found this library. But the c++ made it very fat. It might be powerful but not for my needs maybe. This lib is powerful, but very hard to understand for beginners. And if you are an expert, you probably dont need this library. Maybe you want to join this discussion (if you havent already) https://groups.google.com/a/arduino.cc/forum/#!searchin/developers/pcint/developers/GkCunoVbuVA/8rOKCewPLRAJ
If you have any suggestions how to probably improve this, let me know. Thx. https://github.com/NicoHood/IRLremote/blob/master/examples/Advanced/Receive_PinChangeInterrupt_Basic/Receive_PinChangeInterrupt_Basic.ino
~NicoHood