Hi,
I am working on a motorized camera slider and am stuck on a weird problem. There are two switches to stop the slider when it has reached the end. Now, the one is on the far end with a 2,5m cable. This cable is long enough to pick up electromagnetic noise from the motor and trigger an interrupt. digitalRead() turns out to be a lot more reliable than just the interrupt, but I don’t want to poll it with every single loop. So I want to use digitalRead() inside the interrupt.
But for some reason it won’t work. Can you help? I hope it’s just a syntax error.
This works:
void setup() {
contactLeft = digitalRead(buttonStopLeft);
attachInterrupt(digitalPinToInterrupt(buttonStopLeft), contactToggleLeft, CHANGE);
}
void contactToggleLeft(){
static uint32_t lastInterruptTimeLeft = 0;//Debounce
if(millis() - lastInterruptTimeLeft > debounce){
contactLeft = !contactLeft;
if(contactLeft == true && slideDirection == -1){
md.setM1Speed(0);
}
}
lastInterruptTimeLeft = millis();
}
This doesn't:
void setup() {
attachInterrupt(digitalPinToInterrupt(buttonStopLeft), contactToggleLeft, RISING);
}
void contactToggleLeft(){
static uint32_t lastInterruptTimeLeft = 0;//Debounce
if(millis() - lastInterruptTimeLeft > debounce){
if(digitalRead(buttonStopLeft) == HIGH && slideDirection == -1){
md.setM1Speed(0);
}
}
lastInterruptTimeLeft = millis();
}