Hey all, I'm trying to rig up 3 bike wheels and get ticks from the wheels for RPMs.
I'm using Serial.write and such to send data to Max7.
I have three basic problems with the code that follows that I don't understand:
-
I can only get Pin 2 & 3 to work, I replace the (digitalPinToInterrupt(9): nine with
another pin and it doesn't work. Only 2 & 3 work. Any ideas why? -
How can I do this with 3 sensors? I tried creating three sets of the code, but I'm not
sure I'm doing it right. Any suggestions would help. See below. -
What is that first "Serial.begin(115200)" line do?
volatile byte half_revolutions;
unsigned int rpm;
unsigned long timeold;
void setup()
{
Serial.begin(115200);
// pinMode(2, input);
attachInterrupt(digitalPinToInterrupt(9), magnet_detect, RISING);//Initialize the intterrupt pin (Arduino digital pin 2)
half_revolutions = 0;
rpm = 0;
timeold = 0;
Serial.begin(9600);
}
void loop()//Measure RPM
{
if (half_revolutions >= 20) {
rpm = 30*1000/(millis() - timeold)*half_revolutions;
timeold = millis();
half_revolutions = 0;
Serial.println(rpm,DEC);
}
}
void magnet_detect()//This function is called whenever a magnet/interrupt is detected by the arduino
{
half_revolutions++;
Serial.println("detect");
Serial.write(1);
}
//////////////////////////////////////// SENSOR 2 ////////////////////////////////////////