hall effect sensor as a rpm mesauerment device

on a side note, i wrote some code to count how many times a button is pressed, and to only measuer the state changes.

here is that.

int ledPin = 12; // LED connected to digital pin 13
int inPin = 2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int cnt =0; // var for counting the presses
int tog =0; //bit used to toggle and keep track of when the button is pressd or not

void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
pinMode(inPin, INPUT); // declare pushbutton as input
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps

}

void loop() // run over and over again
{
val = digitalRead(inPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
if (tog ==0){
tog++;}
else{
while ( tog == 1) {
cnt++;
Serial.print(cnt, DEC);
Serial.print("\t");
Serial.print(tog, DEC);
Serial.print("\t");
tog = 2;
}
}
}
else
{
digitalWrite(ledPin, HIGH); // turn LED ON
tog =0;
}
}

can i just replace the push button with the hall effect sensor?