Go Down

Topic: Revolutions Per Minute Calculating Error (Read 2 times) previous topic - next topic


Jul 15, 2012, 02:15 am Last Edit: Jul 16, 2012, 10:37 pm by Nick Gammon Reason: 1
Thanks for all your help, I fixed it.

Code: [Select]
//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
#define Reed 3 //pin for the switch

//create a timer
StopWatch MySW (StopWatch::MICROS);
//state of sensor 1 or 0
byte reedState=0;
//time between pass of magnet
unsigned long timeSincePass=0.0;
//revolutions per second
float RPS=0.0;
//revolutions per minute
float RPM=0.0;
//last state
byte lastreedState=0;

//just some setup stuff
void setup()
 lcd.begin(16, 4);

void loop()
 //get the state of the sensor;
 //time since pass of magnet
 timeSincePass= MySW.elapsed();
 //set the lcd cursor to write on the second line

 //if the magnet engages the switch
 if (reedState != lastreedState && reedState==HIGH)
   //turn on status led for visual purposes
   //convert milliseconds to seconds
   //reset the timer storage int    
   //reset the timer and start it again


 if (reedState==HIGH)
   digitalWrite(LED, HIGH); // gives a visual aid to tell when it is being magnetized

   digitalWrite(LED, LOW); //Turns off when no magnet is detected

 //convert seconds to minutes

 //print the results to a screen
 lcd.setCursor(0, 1);
 lcd.print("Time  ");
 lcd.print(" MPH ");
 lastreedState = reedState;


Moderator edit: [code] ... [/code] tags added. (Nick Gammon)
Proud Member of the Nighthawk Robotics Club Team 569 B

Go Up