I am using a microswitch to count a very slow motor turns (5 turns per minute).
When I get the pulse from the switch I need to print out on serial a message and the application on the other side calculate the time between impulses and manage other features.
My problem is that being the motor very slow the microswitch is closed for 700 ms sending out for all that time messages on the serial and I need to send out a single impulse instead.
The switch is normally grounded and it gets the 5 V only when is closed, I am then measuring the voltage on an analog input and if the voltage is close to 5 I print out the message. meesStart and messEnd are simply ><.
This is my code:
//Lettura numero giri
int giri= analogRead(A5);
float voltage = giri*(5.0/1023.0);
if (voltage > 4.5)
String giriHeader = "N0001";
How can I get out a single Serial.println each time the switch is closed (even if it is closed for 1 second).