I measure the magnetic field. And I wanted to calculate the average value of the magnetic field after 60s if I press the 1. So when I press one in serial monitor after 60s it gives me the average value. How can I do that with the millis function ?
When your switch is closed, start recording your readings in an array or just increment a variable by the read value. Also record the current value of millis( ) and enable a Flag.
When the Flag is enabled, check if 60000 ms has expired.
So I am understanding this as you want to get rid of using the 1 key to get the avg via serial.
So in setup use prev= millis() so prev holds the start time.
Then in your loop check to see if 60000 millisecs have elapsed using
if (millis()-prev > 60000) {
//then in here do what you need to do
prev=millis() //reset prev to start from present time
}