I'm having a slight problem that I'm unable to work out. I am using an arduino Uno to print an incremental, but predefined wheel circumference. This is all working beautifully except it gives a negative reading during execution, and then runs into the positive etc. Without being exact, the output is something like the following:
1.85, 3.71, 5.56, 7.41, 9.27, 11.15....
When this multiple reaches 32.00 or greater, it then counts negatively back down to zero, then positively up to 32.00 again.
I can't quite work out why this would be, so hoping that one of you guys would be able to shed some light. The code is as follows:
#include <Arduino.h>
int InterruptPin = 2;
int circ = 1854; //mtrs
int km = 0;
void calculate(){
km = km + circ;
//float temp = km / 1000;
float temp = (float)km / (float)1000;
Serial.println(temp);
}
void setup(){
pinMode(InterruptPin, INPUT);
attachInterrupt(digitalPinToInterrupt(2), calculate, RISING);
Serial.begin(9600);
}
void loop(){
}