explanation some steps in code to measure frequency

Hey guys,
i have connect a wind sensor to arduino mega
wind sensor data sheet is
http://www.windandsun.co.uk/media/277060/NRG-40C-Anemometer-data-sheet.pdf
connection diagram of system has attached
the purpose of system is to record wind speed which be calculated as follow:

wind speed=o/p frequency*0.765+0.35
i surfed net and found this sketch and i made necessary modification
actually i don’t understand some steps in sketch
please:don not replay with lmgtfy

long freq, tempo,wind_speed;
int pulsos;
boolean pulso;
void setup() {
  // put your setup code here, to run once:
pulso=HIGH;
pinMode(2,INPUT);
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:void loop() {
 [color=red] tempo = millis();
  if(digitalRead(2)==HIGH)
  {
    if(pulso==HIGH)
    {
pulsos = pulsos + 1;
    }

pulso=LOW; 

  }
else{
pulso=HIGH;
  }

  if(tempo%2000==0){
freq = pulsos;[/color]
wind_speed=freq*0.765+0.35;
Serial.print("wind speed=  ");
 Serial.print(wind_speed);
 Serial.print("   m/s");
 Serial.print("\t");
Serial.print("frequency= ");
 Serial.print("\t");
Serial.print(freq);
 Serial.print("\t");
Serial.println("Hz");



pulsos=0;  
delay (5000);

  }

}

i dont understand the function of this part

tempo = millis();
  if(digitalRead(2)==HIGH)
  {
    if(pulso==HIGH)
    {
pulsos = pulsos + 1;
    }

pulso=LOW; 

  }
else{
pulso=HIGH;
  }

  if(tempo%2000==0){
freq = pulsos

"tempo" should be "unsigned long"

"pulso" is a boolean - it should not have the value HIGH or LOW.

tempo = millis();   //save the current value od millis() (note comment from AWOL)
if (digitalRead(2) == HIGH) //if pin 2 is HIGH
{
  if (pulso == HIGH)  //if the pulso variable is HIGH (note comment from AWOL)
  {
    pulsos = pulsos + 1;  //add 1 to pulsos
  }
  pulso = LOW;  //change the state of pulso to LOW
}
else
{
  pulso = HIGH; //if pin 2 is not HIGH set pulso to HIGH
}

if (tempo % 2000 == 0)  //if the value of tempo is divisible by 2000 with no remainder
{
  freq = pulsos //copy the value of pulsos to the freq variable

The result of this section of code is to count HIGH pulses on pin 2 for 2000 milliseconds

AWOL:
"pulso" is a boolean - it should not have the value HIGH or LOW.

It being a boolean variable means it can have either of 2 states in Boolean (or Boolian) mathematics according to it's inventor George B. There are no other states available then HIGH or LOW.

void setup() {
  Serial.begin(9600);
  if (HIGH==true) Serial.println("HIGH==true");
  Serial.println(HIGH,DEC);
  Serial.println(true,DEC);
  if (LOW==false) Serial.println("LOW==false");
  Serial.println(LOW,DEC);
  Serial.println(false,DEC);
}
void loop() {}

Deva_Rishi:
There are no other states available then HIGH or LOW.

You'll have to do better than that - please show which of Bool's works mentions HIGH or LOW.

AWOL:
You'll have to do better than that - please show which of Bool's works mentions HIGH or LOW.

It is not about the name ! it is about the number of states.

Deva_Rishi:
It is not about the name ! it is about the number of states.

Ah! But it is about the name.
An output pin could be HIGH, LOW or tristate.

AWOL:
Ah! But it is about the name.
An output pin could be HIGH, LOW or tristate.

and this tristate of yours you can write using digitalWrite() ?? and it is defined as ehm undefined isn’t it ! and comparing it to either true or false ? hmm, tristate is an electronic state, not a logical state. Logical comparisons like (HIGH !=false) = true, (true | LOW) = true etc.

this tristate of yours you can write using digitalWrite() ??

No, but it is a well defined state for an I/O pin. I suggest to look it up.

void loop()
{
  // put your main code here, to run repeatedly:void loop() {
  tempo = millis();
  if (digitalRead(2) == HIGH)
  {
    // 'pulso' is set to the opposite of the previous input value
    // so if both are HIGH the signal went from LOW to HIGH
    if (pulso == HIGH)
    {
      pulsos = pulsos + 1;
    }

    pulso = LOW;  // Opposite of input
  }
  else
  {
    pulso = HIGH;  // Opposite of input
  }

  // Every two seconds...
  if (tempo % 2000 == 0)
  {
    freq = pulsos;  // Record pulses per two seconds.  If two pulses per rev, this is revs per second
    wind_speed = freq * 0.765 + 0.35;  // Calculate wind speed
    Serial.print("wind speed=  ");
    Serial.print(wind_speed);
    Serial.print("   m/s");
    Serial.print("\t");
    Serial.print("frequency= ");
    Serial.print("\t");
    Serial.print(freq);
    Serial.print("\t");
    Serial.println("Hz");

    pulsos = 0;  // Restart the pulse counter
    delay (5000);  // ?????
  }

Deva_Rishi:
and this tristate of yours you can write using digitalWrite() ??

Well, yes. Yes I can.
I run my own modified Arduino core, and "digitalWrite (pin number, TRIS);" makes a lot of things like charlieplexing simpler and more flexible.

AWOL:
Well, yes. Yes I can.
I run my own modified Arduino core, and "digitalWrite (pin number, TRIS);" makes a lot of things like charlieplexing simpler and more flexible.

Oh well that is great, so you do pinMode(pin,INPUT);
How wonderful and how do you #define TRIS 2 ?? it is amazing, you change the pin 'mode'

so you do pinMode(pin,INPUT);

No, that would be silly, and very wasteful.

how do you #define TRIS 2 ??

Again, no. How terribly old-fashioned that would be.

Is there something wrong with your '?' key?

johnwasser:

void loop()

{
  // put your main code here, to run repeatedly:void loop() {
  tempo = millis();
  if (digitalRead(2) == HIGH)
  {
    // 'pulso' is set to the opposite of the previous input value
    // so if both are HIGH the signal went from LOW to HIGH
    if (pulso == HIGH)
    {
      pulsos = pulsos + 1;
    }

pulso = LOW;  // Opposite of input
  }
  else
  {
    pulso = HIGH;  // Opposite of input
  }

// Every two seconds...
  if (tempo % 2000 == 0)
  {
    freq = pulsos;  // Record pulses per two seconds.  If two pulses per rev, this is revs per second
    wind_speed = freq * 0.765 + 0.35;  // Calculate wind speed
    Serial.print("wind speed=  ");
    Serial.print(wind_speed);
    Serial.print("  m/s");
    Serial.print("\t");
    Serial.print("frequency= ");
    Serial.print("\t");
    Serial.print(freq);
    Serial.print("\t");
    Serial.println("Hz");

pulsos = 0;  // Restart the pulse counter
    delay (5000);  // ?????
  }

thank you very much i understand from your replay that there is no need for this statement
delay(5000)