Ok now I'm getting somewhat more realistic numbers like 200 and 250 revs per second, but still those are the only 2 readings I'm getting.
//these are just some references for it to work properly
#include <StopWatch.h>
#include <LiquidCrystal.h>
//these are the microcontroller ports that an lcd screen is connected to, a status led, and the switch.
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
#define LED 13 //pin for the LED indicator (green)
#define Reed 3 //pin for the switch
//create a timer
StopWatch MySW;
//state of sensor 1 or 0
byte reedState=0;
//time between pass of magnet
float timeSincePass=0;
//revolutions per second
float RPS=0;
//revolutions per minute
float RPM=0;
//last state of reed switch on or off
byte lastReedState=LOW;
long lastDebounceTime = 0;
long debounceDelay = 50;
//just some setup stuff
void setup()
{
pinMode(LED,OUTPUT);
pinMode(Reed,INPUT);
Serial.begin(9600);
lcd.begin(16, 4);
lcd.print("Your Revs/Sec");
}
void loop()
{
byte reading = digitalRead(Reed);
//get the state of the sensor;
//time since pass of magnet
timeSincePass= MySW.elapsed();
//set the lcd cursor to write on the second line
lcd.setCursor(0, 1);
if (reading != lastReedState)
{
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay)
{
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
reedState = reading;
}
//if the magnet engages the switch
if (reedState==HIGH)
{
//turn on status led for visual purposes
digitalWrite(LED, HIGH);
//convert milliseconds to seconds
RPS=(float)1000/timeSincePass;
//reset the timer storage int
timeSincePass=0;
//reset the timer and start it again
MySW.reset();
MySW.start();
}
else
{
//turn off led otherwise
digitalWrite(LED, LOW);
}
//convert seconds to minutes
RPM=(float)RPS*60;
//print the results to a screen
lcd.print(RPS);
lcd.print(" ");
lcd.print(timeSincePass);
lastReedState = reading;
}