Trying to get a bike computer working: two reed switches, one for pedal rotations, one for wheel rotations. Tried without ISRs - simple loop polling for digitalRead on pins 2 and 3 - works except it misses rotations when the wheel spins too fast.
Initial attempt w ISRs:
volatile unsigned int pedalCount = 0;
volatile unsigned long wheelCount = 0;
void setup() {
pinMode(2, INPUT);
pinMode(3, INPUT);
attachInterrupt(2, incPedal, RISING);
attachInterrupt(3, incWheel, RISING);
...
void incPedal() {
pedalCount++;
}
void incWheel() {
wheelCount++;
}
... which does not work, in part because pin interrupts use different pin definitions than Digispark's pinout, but if there's an easy fix?
tried Arduino's attachInterrupt(digitalPinToInterrupt(pin), blink, CHANGE); but the digitalPinToInterrupt function is not supported by Digispark.
tried to use TinyPinChange:
#define FIRST_INPUT 2
#define SECOND_INPUT 3
volatile uint16_t FirstInputChangeCount = 0;
volatile uint16_t SecondInputChangeCount = 0;
uint8_t VirtualPortNb;
uint8_t VirtualPortNb_;
void setup()
{
TinyPinChange_Init();
VirtualPortNb = TinyPinChange_RegisterIsr(FIRST_INPUT, InterruptFunctionToCall);
VirtualPortNb_ = TinyPinChange_RegisterIsr(SECOND_INPUT, InterruptFunctionToCall);
TinyPinChange_EnablePin(FIRST_INPUT);
TinyPinChange_EnablePin(SECOND_INPUT);
etc ...
which compiles fine, but InterruptFunction never gets called. Anyone know what I'm doing wrong?
My apologies if this is too basic. I am new to this. I did read all the forum posts on this subject, read Arduino's documentation and Nick Gammon's treatise and more before posting, and tried the TinyPinChange and PinChangeInterrupt libraries. Still stuck.
Thanks very much