Modifying a library source code

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
wdickenson
 
Posts: 184
Joined: Fri Nov 16, 2012 8:43 pm

Modifying a library source code

Post by wdickenson »

I am working with a device (lightning detector) that has a code sample (AS3935-Arduino-Library-I2C). It "requires" an interrupt but I have already consumed the two default interrupts on the UNO and I hate to switch to the Mega just for this. Now I don't have the hardware yet so I can't experiment so it's possible the code will work fine, I just don't know.

So I think I know how to set a 3rd pin (Digitial pin 8) as an interrupt (PCINT4?) but looking at the code if I supply it pin 8, the structure of the library won't work. It seems I have two choices ....

1) Feed pin 8 to the library. I am pretty sure it won't work but thats ok, because I can do that "manually" outside the library OR
2) Modify the .cpp so that it uses one of the PC interrupts

I have never modified a .cpp file in Arduino land so this is a first for me. Which would be better ? What do I need to modify the .cpp ?

Thanks
Attachments
AS3935-Arduino-Library-master.zip
(11.27 KiB) Downloaded 21 times

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Modifying a library source code

Post by adafruit_support_mike »

That's one of those cases where there are no 'right' choices. You just have to decide which one you prefer and do that until you get things working, or you decide to abandon that approach and try the other option.

Any pin on the Arduino can generate a Pin Change Interrupt, but you don't get much specific information from the interrupt. A change on any pin in the same port will trigger the same interrupt service routine, so you can't tell which pin changed or whether its new value is HIGH or LOW without examining the port registers.

You can use the interrupt enable mask to narrow down the list of pins that trigger the ISR though, giving you a bit more control oevr the set of interrupts you want to handle at any given moment.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”