Millis help please!

A switch has four states:

  • Was open now open (state 0) : Switch is released (OPEN)
  • Was open now closed (state 1) : Switch was just pressed (RISING)
  • Was closed now closed (state 2) : Switch is pressed (CLOSED)
  • Was closed now open (state 3) : Switch was just released (FALLING)

Basically. As soon and I press and hold a button. I want it to start counting from 0 on up until I release the button. I'd like to serial print it in tenths of a second.

You want to start the chronometer on the RISING edge and print it on the FALLING edge.

Start in state 0
if the state is 0: read the switch. if it is closed change state to 1
if the state is 1: set the chronometer @ millis(); change state to 2
if the state is 2: read the switch. if it is open: change state to 3
if the state is 3: print ((millis() - chronometer) / 100); change state to = 0

Jacques