Newbie here, so sorry if this is in the wrong place!
having a few issues with reading a pulsed flow meter through digital pin 4. Pins 2,3,7 & 10 are all functioning.
Is this because pin 4 works in a different way?
Code below:
#include <EnableInterrupt.h>
#include <TimerOne.h>
// Pulse Count x5 on Leonardo
// Variables
const int ledPin = 13;
const byte pulsePin2 = 2;
const byte pulsePin3 = 3;
const byte pulsePin4 = 7;
const byte pulsePin7 = 10;
const byte pulsePin10 = 4; // choose pin
volatile long pulsePinCounter1= 0;
volatile long pulsePinCounter2= 0;
volatile long pulsePinCounter3= 0;
volatile long pulsePinCounter4= 0;
volatile long pulsePinCounter5= 0; // new
const byte pulsePin4 = 7;
const byte pulsePin7 = 10;
const byte pulsePin10 = 4;
I assume that those variable names make sense to you but they could, at the very least, be confusing
Which Arduino board are you using ?
Please look at Read this before posting a programming question and follow the instructions about how to post code
Thanks for the quick reply. Edited the original post!
Yes completely right the varibale names made sense before I started changing the order of pins!
Using a Leonardo.
Thanks for adding the code tags
Variable names generally make more sense if they give an indication of their function rather than being generic
Is this because pin 4 works in a different way?
Using a Leonardo.
Pin 4 on the Leonardo does not support either an external or pinchange interrupt.
From the "Read Me" section of the library EnableInterrupt.h
On the Leonardo there are 7 pin change interrupt pins in addition
to the 5 external interrupt pins. See PIN BESTIARY below for the pin numbers and
other details.
Arduino Leonardo
Interrupt Type |
Pins |
External |
0-3 and 7 |
Pin Change |
8-11 and SCK, MOSI, MISO |
Perfect. Thanks very much Cattledog