You are on page 1of 1

//https://forum.arduino.cc/index.php?topic=401987.

0
// count encoder pulses on a motor

volatile unsigned long count = 0; // +1 each time interrupt calls


ISR
unsigned long copyCount = 0; // accumulates the interrupt
count, after
unsigned long lastRead = 0;
unsigned long interval = 100; // interval must be set <= delay
(eg 100, 100) set in the loop otherwise rps becomes amplified upwards
unsigned long speed = 0;

void setup()
{
Serial.begin(9600);

pinMode(2, INPUT_PULLUP); // set pin 2 as input and high


when no input
attachInterrupt(0, isrCount, RISING); // interrupt programme when signal
to pin 2 detected (0 = pin 2 and 1 = pin 2)
// count when rising, call ISR
function when happens (irs = interupt service routine)

// pinMode(21, INPUT); // ?
// attachInterrupt(digitalPinToInterrupt(21), speed, FALLING); // ?
}

You might also like