Created
February 21, 2011 00:42
-
-
Save bananastalktome/836478 to your computer and use it in GitHub Desktop.
The code, still rough though.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int inPin = 7; // pushbutton connected to digital pin 7 | |
//const int cmPerClick = 51; // cm | |
const float inchesPerClick = 20.1; // inches | |
int val = 0; // variable to store the read value | |
float totalDistance = 0; // total distance in inches | |
int lastTime = 0; | |
float difference = 0; | |
int time = 0; | |
boolean clickRead = false; | |
float rps = 0; | |
float runningSpeed = 0; | |
String output = ""; | |
float numberOfSeconds = 0; | |
void setup() | |
{ | |
Serial.begin(9600); | |
pinMode(inPin, INPUT); // sets the digital pin 7 as input | |
} | |
void loop() | |
{ | |
val = digitalRead(inPin); // read the input pin | |
time = millis(); | |
if (val == HIGH && clickRead == false) | |
{ | |
difference = time - lastTime; | |
numberOfSeconds = difference / 1000.0; | |
rps = 1.0 / numberOfSeconds; | |
runningSpeed = 3 * rps * 6.28; | |
//runningSpeedMiles = runningSpeed / 63360; | |
totalDistance += inchesPerClick; | |
// output = String(String(runningSpeed) + " Inches/Sec (" + String(totalDistance) + " inches traveled)"); | |
// Serial.println(output); | |
Serial.print(runningSpeed); | |
Serial.print(" Inches/Sec ("); | |
Serial.print(totalDistance); | |
Serial.print(")\n"); | |
clickRead = true; | |
lastTime = time; | |
} | |
else if (val == LOW && clickRead == true) | |
{ | |
clickRead = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment