Bear with me guys, I've been studyin' this stuff for days but I'm still not sure where to go next.
Here's where I am and what I "think" I know.
The Code
// read MPH
volatile int mphcount = 0;//see http://arduino.cc/en/Reference/Volatile
int mph = 0;
unsigned long lastmillis = 0;
void setup(){
Serial.begin(9600);
attachInterrupt(0, mph_anemometer, FALLING);//interrupt zero (0) is on pin two(2).
}
void loop(){
if (millis() - lastmillis == 60000){ /*Uptade every minute, this will be equal to number of pulses.*/
detachInterrupt(0); //Disable interrupt when calculating
mph = mphcount / 104; /* Convert pulsecount to MPH.*/
Serial.print("MPH =\t"); //print the word "MPH" and tab.
Serial.print(mph); // print the mph value.
Serial.print("\t pulsecount=\t"); //print the word "pulses".
Serial.println(mphcount); /*print pulses per minute. And print new line or enter.*/
mphcount = 0; // Restart the MPH counter
lastmillis = millis(); // Uptade lasmillis
attachInterrupt(0, mph_anemometer, FALLING);//enable interrupt
}
}
void mph_anemometer(){ /* this code will be executed every time the interrupt 0 (pin2) gets low.*/
mphcount++;
}
I'm currently sending my results to the Serial Monitor as an integer?
I would like to write my results in a BCD form to pins 3-10 to get 2 digits of decimal for 7 segment Led's using 7447 chips. 0-99 is as high as I'll need to go. This is all about my homemade anemometer and if the wind is over 100mph I ain't goin' outside anyway!
What I think I need to do:
-
1st of all, declare the pin (array?) as outputs up top.
-
I don't think I need to do anything in setup. But I could be wrong. :o
-
In the loop I need to digitalwrite something, but what? I've seen Disp/BIN but a straight binary output isn't gonna give me a 2 digit decimal result. Is there a Disp/BCD?
Any pointers are appreciated.