jwan
1
float value=0;
float rev=0;
int rpm;
int oldtime=0;
int time;
void isr()
{
rev++;
}
void setup()
{
Serial.begin(9600);
attachInterrupt(0,isr,RISING);
}
void loop()
{
delay(1000);
detachInterrupt(0);
time=millis()-oldtime;
rpm=(rev/time)*60000;
oldtime=millis();
rev=0;
Serial.print("n0.val=");
Serial.print(rpm);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
attachInterrupt(0,isr,RISING);
}
Interrupt 0 uses pin 2 on most (all ?) Arduinos so you cannot change it to use pin 8
You could consider using Pin Change Interrupts
the atmega328p supports interrupt on pins 2 and 3 so 0 mean pin 2 and 1 means pin 3
jwan
4
m_k_akash:
the atmega328p supports interrupt on pins 2 and 3 so 0 mean pin 2 and 1 means pin 3
I use arduino nano, im beginner to use it can you help pls and write how is it work ?PLS
jwan
5
UKHeliBob:
Interrupt 0 uses pin 2 on most (all ?) Arduinos so you cannot change it to use pin 8
You could consider using Pin Change Interrupts
how using Pin Change Interrupts, can you pls write it?
How about you try writing it yourself ? You will then learn something
Did you write teh code that you posted ?
Maybe start by looking at Pin Change Interrupts and the pages, including an example, that it links to
jwan
7
UKHeliBob:
How about you try writing it yourself ? You will then learn something
Did you write teh code that you posted ?
Maybe start by looking at Pin Change Interrupts and the pages, including an example, that it links to
i got it from internet and i tried to change input to input 8 I dont know how to change it, i can't find were is the input 2 in the code
were is the input 2 in the code
Read reply #2
The 0 in attachInterrupt() tells the program to use pin 2
jwan
9
UKHeliBob:
Read reply #2
The 0 in attachInterrupt() tells the program to use pin 2
THANK YOUU a LOOOT and BIIIG LIIIKE
Paul_B
10
The more serious question is why is a "newbie" using interrupts where they are inappropriate, and why using floats? 
Robin2
11
And, to my mind, even more interesting is WHY the OP wants to move from pin2 to pin8.
If we knew that then it would probably be much easier to provide useful information.
...R