OK I tried various versions of what you suggested and came up with one that works only problem is i have no idea why it works can you take a look at the following and tell me why this works, but it works perfect?
/* 1st attempt to make a distance counter for a wheelchair.
Switch is a momentary switch on right wheel that is 22" diamater.
Axel has a cam that pushes switch each single rotation. */
#include <LiquidCrystal.h>
/*
LCD Connections:
rs (LCD pin 4) to Arduino pin 12
rw (LCD pin 5) to Arduino pin 11
enable (LCD pin 6) to Arduino pin 10
LCD pin 15 to Arduino pin 13
LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
*/
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int led = 13; // pin 13 shows button activity
int x;
float y;
float z;
int d;
long m;
const int Button1 =7 ; // assigns input 7
void setup() {
pinMode(led, OUTPUT);
digitalWrite(Button1, HIGH); //turn on internal pull up
x=0; //rotation button
y=5.759; //circumfrence of wheel in feet
z=0; //feet traveled so far
m=5280; // feet per mile
lcd.begin(16, 2); // rows, columns. use 16,2 for a 16x2 LCD, etc.
lcd.clear(); // start with a blank screen
lcd.setCursor(0,0); // set cursor to column 0 row 0
}
void loop(){
if(digitalRead(Button1) == LOW)
{
while(digitalRead(Button1)== LOW);
x++;} //Increments x by one if Button 1 is Low
digitalWrite(led, LOW); //Sets Pin 13 low Led is off.
{
digitalWrite(led, HIGH);} //Sets Pin 13 high if button is not pushed
z=x*y; //Rotations times distance per rotation= feet traveled
d=z/m; //Feet traveled / 5280(feet per mile)
lcd.print("Feet: ");
lcd.print(z); //Prints numeric amount of feet
lcd.setCursor(0,1);
lcd.print("Miles:");
lcd.print(d); //Prints numeric amount of feet
lcd.setCursor(0,0); //Resets dispay.
}