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);
}
}
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() {}
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.
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'
{
// 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");