Arduino mkr gsm 1400 interrupt

Hi!
I'm new with the posting here, but i always found solutions to my problems, but now i don't get it.
I bought a Arduino MKR GSM 1400 and I want to read how many times a reed switch was activated with interrupt. I saw that interrupt pins for this board are 4,5,6,7,8,A1. But none of those work for me.
Sorry if this question exists, but i haven't found it.
I have this software and it works with uno or mega, but not with mkr gsm 1400. I have a voltage divider for the pin. Because the reed switch is powered at 5V.
Can you please guide me to a solution?
Thank you!

/*Prepared by Hans Huth

  • 1/6/2020
    */

// The bucket tested with this code is summarized here:
// http://texaselectronics.com/media/mconnect_uploadfiles/t/r/tr-525i_rainfall_user_s_manual.pdf

// Testing shows this bucket has a normally open reed switch.

#define RAIN_PIN 2 // replace with your microcontrollers interrupt pin number tied to your rain gauge
#define CALC_INTERVAL 1000 // increment of measurements
#define DEBOUNCE_TIME 15 // referenced in ISR; multiply by 1000 if using a reed switch

unsigned long nextCalc1;
unsigned long timer1;

volatile unsigned int rainTrigger = 0;
volatile unsigned long last_micros_rg;

void setup() {
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(RAIN_PIN), countingRain, RISING);

pinMode(RAIN_PIN, INPUT);
nextCalc1 = millis() + CALC_INTERVAL;
}

void loop() {

timer1 = millis();
// Serial.println(digitalRead(RAIN_PIN));
if(timer1 > nextCalc1) {
nextCalc1 = timer1 + CALC_INTERVAL;
Serial.print("Total Tips: ");
Serial.println((float) rainTrigger);
}
}

void countingRain() {
// ATTEMPTED: Check to see if time since last interrupt call is greater than
// debounce time. If so, then the last interrupt call is through the
// noisy period of the reed switch bouncing, so we can increment by one.
if(((long)(micros() - last_micros_rg) >= DEBOUNCE_TIME*1000)&&(digitalRead(RAIN_PIN)==1)) {
rainTrigger += 1;
last_micros_rg = micros();
}
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.