Help with tachometer

Below is the code for a tachometer I'm building. It's using a OHB900 sensor and finding the rpm of a daisy wheel. The wheel has six "petals" and the sensor detects whenever a petal passes between two plates. Right now my code is supposed to count 6 petals then mark one rotation in an array until it marks 20 rotations. My thought would be to count the amount of time it takes for 20 rotations to happen then divide 20 by that time. Right now, the code only prints 1 over and over to the serial monitor so it doesn't work and I don't know why. As far as timing it I'm assuming i'd use the millis() function to time it, but I'm not quite sure how. I need to time the revolutions not the whole time the code is running. Any help with either issue would be greatly appreciated.

int i, j, k, l, rpm = 0, avg, sum = 0, pin2, petal[6] = {0,0,0,0,0,0}, rotation[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;
void setup()
{
Serial.begin(9600); //Open serial communications with computer
pinMode(2,INPUT); // sets pin 1 as the input pin from sensor
pinMode(3,OUTPUT); // sets pin 3 as output i.e. LED
}
void loop()
{
pin2 = digitalRead(2); // reads input from sensor
if(pin2 == LOW)
{
digitalWrite(3, LOW); // if the daisy wheel is detected, it sets the LED to off
if(pin2 == LOW)//when one of the petals in the daisy wheel is detected, it will add a 1 to an array
{
for(i = 0; petal == 0; i++)//counts through the array

  • {*
    _ if(petal == 0)//until a zero is detected in one of the 6 places_
    * {*
    _ petal = 1;//and adds a 1 in that spot closing the for loop waiting for another petal to be detected
    * }
    }
    }*_

* if(petal[5] == 1)//if all six petals have passed through the sensor*
* {*
* for (j = 0; j < 5; j++)//prints the array showing that six petals were detected*
* {*
* Serial.println(petal[j]);*
* }*
* for(k = 1; rotation[k] == 0; k++)//counts through the array*
* {*
* if(rotation[k] == 0)//until a zero is detected in one of the 20 places*
* {*
* rotation[k] = k;//then marks the number of rotations that is being detected*
* }*
* }*
* if(rotation[19] == 1)*
* {*
* for (l = 0; l < 19; l++)//prints the array showing that all twenty rotations were detected*
* {*
* Serial.println(rotation[l]);*
* }*
* }*
* }*
* }*
* else*
* {*
* delay(500);//waits half a second to set the led on*
* digitalWrite(3, HIGH);// if the wheel isn't detected, the LED is set to high to light up*
* }*
}

_ /from here I'm not sure what to do. This code should work like this. It counts each petal passing through the sensor, when it counts six_
_ it marks it as one rotation in the rotation array, from there it should count the amount of time it takes for all 20 rotations to happen,
and divide 20 rotations by that amount of time. I have no idea how to count the amount of time from when a certain function in a program starts.
There is the millis() function, but it counts the amount of time from the start of the program, not the start of the rotation counting. maybe an if statement could*
limit the function to only counting the time it takes to gather rotations. not sure yet.*/_

quit some code for the task.
I think it would be a better idea to use an interrupt (int=0 on pin 2) to trigger for each petal passing.
..and much less code.

Check my math..

volatile long us1,us2; // for interrupt routine
long difference; // time for 1/6 turn
float rpm; // resulting rpm
long time_to_show_rpm=1000; // 1 sec to 1st show 
int interval_show_rpm=1000; //ms (once a second);

void setup()
{
  Serial.begin(115200); // max serial speed
  attachInterrupt(0, rpm_update, FALLING); //
}

void rpm_update()
{
  us2=us1;
  us1=micros();
}

void loop()
{ 
  // do someting useful
  if (millis()>time_to_show_rpm) // show rpm.data
  {
    // calculate rpm
    difference=us1-us2;  //(microseconds/rev)
    rpm=10000000.0/difference;
    Serial.println(rpm,1);
    time_to_show_rpm+=interval_show_rpm;
  }
}