Calculate Period Between Pulse

So some background: Building an arduino tachometer for my motorcycle, taking the tachometer signal that is already on the bike, routing it through and optocoupler and into the Arduino Uno. Getting a "expected primary expression before do" and a "output was not declared in this scope." Can I get somebody to take a look at my code and tell me what I'm doing wrong? Any critiques or suggestions appreciated.

volatile int RPMpulses = 0;
volatile unsigned long firstpulse = 0;
volatile unsigned long lastpulse = 0;
volatile int period = 0;
String string1 = "Engine Speed =";

unsigned long lastRefresh = millis();
const int refreshInterval = 250;
const int tachpin = 1;


void setup(){
  Serial.begin(96000);
  attachInterrupt(tachpin,countRPM,RISING);
}
  
void countRPM()
{
  RPMpulses++;
  if(RPMpulses > 1) {
    lastpulse = millis();
  }
  else {
    firstpulse = millis();
  }
}

void loop() {

  if((millis() - lastRefresh) > refreshInterval) {

    if(RPMpulses>1) {                       //make sure the engine is running
      (do period=(lastpulse-firstpulse)/RPMpulses)
      output period)
    }
    else {
      (output zero)
    }
    RPMpulses = 0;
    lastRefresh = millis();
  }
  Serial.print (string1+period)
}

This lines:

      (do period=(lastpulse-firstpulse)/RPMpulses)
      output period)

and

      (output zero)

Are not "Arduino language" so he don't understand they.

What you want to do?

Thanks, this was an example that I got from someone on reddit. I want to calculate the time difference between the first and last pulse to extrapolate to RPM. There are two pulses for each engine revolution.

Maybe something like this may work:

volatile int RPMpulses = 0;
volatile unsigned long firstpulse = 0;
volatile unsigned long lastpulse = 0;
volatile int period = 0;
String string1 = "Engine Speed =";

unsigned long lastRefresh = millis();
const int refreshInterval = 250;
const int tachpin = 1;


void setup(){
  Serial.begin(96000);
  attachInterrupt(tachpin,countRPM,RISING);
}
  
void countRPM()
{
  RPMpulses++;
  if(RPMpulses > 1) {
    lastpulse = millis();
  }
  else {
    firstpulse = millis();
  }
}

void loop() {

  if((millis() - lastRefresh) > refreshInterval) {

    if(RPMpulses>1) {                       //make sure the engine is running
      period=(lastpulse-firstpulse)/RPMpulses;
    }
    else {
      period = 0;
    }
    RPMpulses = 0;
    lastRefresh = millis();
    Serial.print (string1+period);
  }
}

That works!! Thanks.

I would suggest a copy paste error. As was pointed out:

This lines:
Code:
      (do period=(lastpulse-firstpulse)/RPMpulses)
      output period)

and

Code:
      (output zero)

Are not "Arduino language" so he don't understand they.

Makes no sense whatsoever.
There are one or more syntax errors on each and every line
Hint: the semicolon is used to end a line and your parentheses don't match... Each' (' requires a matching ')' .
You might explore your IDE a little more... You could get lucky and find both Ctrl T and the verify button
Ctrl T would have pointed out all of your errors that verify didn't...

Doc

Thanks Doc. I plugged it in at my desk without the optocoupler connected, expecting to get a serial monitor full of EngineSpeed=0. However, I'm getting a garbled text that looks like this:

Æ8?ÐP^¨?hÛÐ 
Æ8?ÐP^¨?hÛÐ
Æ8?ÐP^¨?hÛÐ
Æ8?ÐP^¨?hÛÐ
Æ8?ÐP^¨?hÛÐ
Æ8?ÐP^¨?hÛÐÆ8?ÐP^¨?hÛÐÆ8?ÐP^¨?hÛÐ
Æ8?ÐP^¨?hÛÐÆ8?ÐP^¨?hÛÐ
Æ8?ÐP^¨?hÛÐÆ8?ÐP^¨?hÛÐ
Æ8?ÐP^¨?hÛÐ
Æ8?ÐP^¨?hÛÐ
Æ8?ÐP^¨?hÛÐ
Æ8?ÐP^¨?hÛÐ
Æ8?ÐP^¨?hÛÐ

Any suggestions about this garbled text, or will this be resolved when I actually have the circuit connected.

This is I believe why you are seeing garbage, Albeit consistent garbage...
Serial.begin(96000); ... One too many zero's..

Doc