Go Down

Topic: PinChangeInt within a custom library (Read 933 times) previous topic - next topic

fuzzball27

Howdy,
I'm working with PinChangeInt in my custom library, and I am curious how to use the attach interrupt function with a private function in my class? Here is my code:
.h:
Code: [Select]
#ifndef RXTX_H
#define RXTX_H
#include    "Arduino.h"

class RxTx
{
public:
    RxTx(byte ch1, byte ch2, byte ch3, byte ch4, byte bat);
    ...
private:
    void calcThrottle();
    void calcAileron();
    void calcElevator();
    void calcRudder();
};

#endif

.cpp:
Code: [Select]

#include    <Arduino.h>
#include    <RxTx.h>
#include    "/Applications/Arduino.app/Contents/Resources/Java/libraries/PinChangeInt/PinChangeInt.h"

...

byte throttle;
byte aileron;
byte elevator;
byte rudder;

...


RxTx::RxTx(byte ch1, byte ch2, byte ch3, byte ch4, byte bat)
{
    init();

    pinMode(ch1, INPUT);
    pinMode(ch2, INPUT);
    pinMode(ch3, INPUT);
    pinMode(ch4, INPUT);
    pinMode(bat, OUTPUT);
   
    digitalWrite(bat, LOW);
   
    throttle = ch3;
    aileron = ch1;
    elevator = ch2;
    rudder = ch4;
   
    //This is where I'm attaching the interrupts
    PCintPort::attachInterrupt(throttle, calcThrottle, CHANGE); // This doesn't work.
    PCintPort::attachInterrupt(aileron, calcAileron, CHANGE); //   It brings up an error that says
    PCintPort::attachInterrupt(elevator, calcElevator, CHANGE);// "No matching function for call to 'PCintPort::attachInterrupt
    PCintPort::attachInterrupt(rudder, calcRudder, CHANGE); //     (byte&, <unresolved overloaded runction type>, int)'"
}

...

//These are the private functions I am trying to attach

void RxTx::calcThrottle()...

void RxTx::calcAileron()...

void RxTx::calcElevator()...

void RxTx::calcRudder()...


As always, help is greatly appreciated! :)
fuzzball27 >>-->

pYro_65


fuzzball27

Thank you so much!
It's too bad there isn't a more convenient and conservative way, but it works!
fuzzball27 >>-->

DuaneB

Hi FuzzBall,

You might have seen that this is the sort of thing that I do all the time on my blog, here for instance -

http://rcarduino.blogspot.com/2012/04/how-to-read-multiple-rc-channels-draft.html

I have previously avoided writing a library because I didn't really see a need, but I have since taken a closer look at some of the existing libraries and while they are great for generic projects and they certainly work as demonstrated by the many people using the link above they are much bigger and slower than they need to be.

I am in the testing stages of a library which drops some of the flexibility to give a smaller, faster, more accurate RC Solution.

If you are at the bench stage of your project, let me know if you would be interested in doing some bench testing of the new library.

Duane B.

rcarduino.blogspot.com




fuzzball27

Hahaha this is perfect... XD

My library is actually based off of one of your blog posts I found some weeks ago. I absolutely loved the way you integrated interrupts and unsigned value types for time efficiency. I very much appreciate the time you've invested in your blog.


I am in the testing stages of a library which drops some of the flexibility to give a smaller, faster, more accurate RC Solution.

If you are at the bench stage of your project, let me know if you would be interested in doing some bench testing of the new library.


That sounds awesome. I would love to try it out.
fuzzball27 >>-->

Go Up