Skip to content

Commit 021412f

Browse files
committed
Merge pull request arduino#441 from mfalkvidd/mfalkvidd/development
Utilize digitalPinToInterrupt in examples
2 parents b623188 + 3433d2d commit 021412f

File tree

8 files changed

+20
-23
lines changed

8 files changed

+20
-23
lines changed

Diff for: libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino

+2-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
#define PULSE_FACTOR 1000 // Nummber of blinks per KWH of your meeter
4949
#define SLEEP_MODE false // Watt-value can only be reported when sleep mode is false.
5050
#define MAX_WATT 10000 // Max watt value to report. This filetrs outliers.
51-
#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
5251
#define CHILD_ID 1 // Id of the sensor child
5352

5453
unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
@@ -74,8 +73,8 @@ void setup()
7473
// Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output
7574
// If no pullup is used, the reported usage will be too high because of the floating pin
7675
pinMode(DIGITAL_INPUT_SENSOR,INPUT_PULLUP);
77-
78-
attachInterrupt(INTERRUPT, onPulse, RISING);
76+
77+
attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, RISING);
7978
lastSend=millis();
8079
}
8180

Diff for: libraries/MySensors/examples/IrrigationController/IrrigationController.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void setup()
184184
pinMode(ledPin, OUTPUT);
185185
pinMode(waterButtonPin, INPUT_PULLUP);
186186
//pinMode(waterButtonPin, INPUT);
187-
attachInterrupt(1, PushButton, RISING); //May need to change for your Arduino model
187+
attachInterrupt(digitalPinToInterrupt(waterButtonPin), PushButton, RISING); //May need to change for your Arduino model
188188
digitalWrite (ledPin, HIGH);
189189
DEBUG_PRINTLN(F("Turning All Valves Off..."));
190190
updateRelays(ALL_VALVES_OFF);

Diff for: libraries/MySensors/examples/LightningSensor/LightningSensor.ino

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
// setup CS pins used for the connection with the lightning sensor
1919
// other connections are controlled by the SPI library)
20-
int8_t CS_PIN = 8;
21-
int8_t SI_PIN = 7;
22-
int8_t IRQ_PIN = 3;
20+
#define CS_PIN 8
21+
#define SI_PIN 7
22+
#define IRQ_PIN 3
2323
volatile int8_t AS3935_ISR_Trig = 0;
2424

2525
// #defines
@@ -60,7 +60,7 @@ void setup()
6060
// function also powers up the chip
6161

6262
// enable interrupt (hook IRQ pin to Arduino Uno/Mega interrupt input: 1 -> pin 3 )
63-
attachInterrupt(1, AS3935_ISR, RISING);
63+
attachInterrupt(digitalPinToInterrupt(IRQ_PIN), AS3935_ISR, RISING);
6464
// dump the registry data to the serial port for troubleshooting purposes
6565
lightning0.AS3935_PrintAllRegs();
6666

Diff for: libraries/MySensors/examples/MotionSensor/MotionSensor.ino

+3-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040
unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
4141
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
42-
#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
4342
#define CHILD_ID 1 // Id of the sensor child
4443

4544
// Initialize motion message
@@ -65,9 +64,9 @@ void loop()
6564

6665
Serial.println(tripped);
6766
send(msg.set(tripped?"1":"0")); // Send tripped value to gw
68-
69-
// Sleep until interrupt comes in on motion sensor. Send update every two minute.
70-
sleep(INTERRUPT,CHANGE, SLEEP_TIME);
67+
68+
// Sleep until interrupt comes in on motion sensor. Send update every two minute.
69+
sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
7170
}
7271

7372

Diff for: libraries/MySensors/examples/MotionSensorRS485/MotionSensorRS485.ino

+3-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858

5959
unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
6060
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
61-
#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
6261
#define CHILD_ID 1 // Id of the sensor child
6362

6463
// Initialize motion message
@@ -84,9 +83,9 @@ void loop()
8483

8584
Serial.println(tripped);
8685
send(msg.set(tripped?"1":"0")); // Send tripped value to gw
87-
88-
// Sleep until interrupt comes in on motion sensor. Send update every two minute.
89-
sleep(INTERRUPT,CHANGE, SLEEP_TIME);
86+
87+
// Sleep until interrupt comes in on motion sensor. Send update every two minute.
88+
sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
9089
}
9190

9291

Diff for: libraries/MySensors/examples/RainGauge/RainGauge.ino

+4-3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
#define LUX_ON // uncomment out this line to enable BH1750 sensor
6060
//#define USE_DAILY // displays each time segment as an accumulation of prior periods inclusive. Comment out to display individual daily rainfall totals in the variables sent to your controller.
6161

62+
#define TIP_SENSOR_PIN 3
63+
6264
#define CALIBRATE_FACTOR 60 // amount of rain per rain bucket tip e.g. 5 is .05mm
6365
#define DHT_LUX_DELAY 300000 //Delay in milliseconds that the DHT and LUX sensors will wait before sending data
6466

@@ -116,7 +118,6 @@ MyMessage msgTrippedVar2(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
116118
#endif
117119
unsigned long sensorPreviousMillis;
118120
int eepromIndex;
119-
int tipSensorPin = 3; // Pin the tipping bucket is connected to. Must be interrupt capable pin
120121
int ledPin = 5; // Pin the LED is connected to. PWM capable pin required
121122
unsigned long dataMillis;
122123
unsigned long serialInterval = 600000UL;
@@ -141,8 +142,8 @@ void setup()
141142
SERIAL_START(115200);
142143
//
143144
// Set up the IO
144-
pinMode(tipSensorPin, INPUT_PULLUP);
145-
attachInterrupt (1, sensorTipped, FALLING); // depending on location of the hall effect sensor may need CHANGE
145+
pinMode(TIP_SENSOR_PIN, INPUT_PULLUP);
146+
attachInterrupt (digitalPinToInterrupt(TIP_SENSOR_PIN), sensorTipped, FALLING); // depending on location of the hall effect sensor may need CHANGE
146147
pinMode(ledPin, OUTPUT);
147148
digitalWrite(ledPin, HIGH);
148149
//

Diff for: libraries/MySensors/examples/VibrationSensor/VibrationSensor.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ MyMessage vibrationMsg(CHILD_ID_VIBRATION, V_LEVEL);
6060
void setup()
6161
{
6262
pinMode(VIBRATION_SENSOR_DIGITAL_PIN, INPUT);
63-
attachInterrupt(1, blink, FALLING);// Trigger the blink function when the falling edge is detected
64-
pinMode(SensorLED, OUTPUT);
63+
attachInterrupt(digitalPinToInterrupt(VIBRATION_SENSOR_DIGITAL_PIN), blink, FALLING); // Trigger the blink function when the falling edge is detected
64+
pinMode(SensorLED, OUTPUT);
6565
}
6666

6767
void presentation() {

Diff for: libraries/MySensors/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include <MySensor.h>
4646

4747
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your sensor. (Only 2 and 3 generates interrupt!)
48-
#define SENSOR_INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
4948

5049
#define PULSE_FACTOR 1000 // Nummber of blinks per m3 of your meter (One rotation/liter)
5150

@@ -87,7 +86,7 @@ void setup()
8786

8887
lastSend = lastPulse = millis();
8988

90-
attachInterrupt(SENSOR_INTERRUPT, onPulse, FALLING);
89+
attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, FALLING);
9190
}
9291

9392
void presentation() {

0 commit comments

Comments
 (0)