Skip to main content
Arduino

Return to Question

added 1 character in body
Source Link

So I want to do something like this:

template<int PIN, int CHANNEL>
void initPin() {
 attachInterrupt(PIN, rising<PIN, CHANNEL>, RISING);
}
template<int PIN, int CHANNEL>
void rising() {
 startTimes[CHANNEL] = micros();
 attachInterrupt(PIN, falling<PIN, CHANNEL>, FALLING);
}
template<int PIN, int CHANNEL>
void falling() {
 values[CHANNEL] = micros() - startTimes[CHANNEL];
 attachInterrupt(PIN, rising<PIN, CHANNEL>, RISING);
}

but the compilecompiler gives me this error

no matches converting function ‘rising’ to type ‘void (*)()’

Can I even do this, or do I have to write all the functions by myself?

So I want to do something like this:

template<int PIN, int CHANNEL>
void initPin() {
 attachInterrupt(PIN, rising<PIN, CHANNEL>, RISING);
}
template<int PIN, int CHANNEL>
void rising() {
 startTimes[CHANNEL] = micros();
 attachInterrupt(PIN, falling<PIN, CHANNEL>, FALLING);
}
template<int PIN, int CHANNEL>
void falling() {
 values[CHANNEL] = micros() - startTimes[CHANNEL];
 attachInterrupt(PIN, rising<PIN, CHANNEL>, RISING);
}

but the compile gives me this error

no matches converting function ‘rising’ to type ‘void (*)()’

Can I even do this, or do I have to write all the functions by myself?

So I want to do something like this:

template<int PIN, int CHANNEL>
void initPin() {
 attachInterrupt(PIN, rising<PIN, CHANNEL>, RISING);
}
template<int PIN, int CHANNEL>
void rising() {
 startTimes[CHANNEL] = micros();
 attachInterrupt(PIN, falling<PIN, CHANNEL>, FALLING);
}
template<int PIN, int CHANNEL>
void falling() {
 values[CHANNEL] = micros() - startTimes[CHANNEL];
 attachInterrupt(PIN, rising<PIN, CHANNEL>, RISING);
}

but the compiler gives me this error

no matches converting function ‘rising’ to type ‘void (*)()’

Can I even do this, or do I have to write all the functions by myself?

Source Link

Pass templated function as attachInterrupt parameter

So I want to do something like this:

template<int PIN, int CHANNEL>
void initPin() {
 attachInterrupt(PIN, rising<PIN, CHANNEL>, RISING);
}
template<int PIN, int CHANNEL>
void rising() {
 startTimes[CHANNEL] = micros();
 attachInterrupt(PIN, falling<PIN, CHANNEL>, FALLING);
}
template<int PIN, int CHANNEL>
void falling() {
 values[CHANNEL] = micros() - startTimes[CHANNEL];
 attachInterrupt(PIN, rising<PIN, CHANNEL>, RISING);
}

but the compile gives me this error

no matches converting function ‘rising’ to type ‘void (*)()’

Can I even do this, or do I have to write all the functions by myself?

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /