Question about unsigned longs

This is probably a silly question as I am new to this

I want to measure the time interval between two buttons being is pressed

the results I am getting are confusing me

movetime = 4294965589 , starttime = 1191, nowtime = 2898

the difference between now and start should = move

also is there any way to search the forum so I do not ask a question that has been answered

my code is below

const int AUTO = 2; const int POWER = 4; unsigned long starttime = 0; unsigned long nowtime = 0; unsigned long movetime = 0;

void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(AUTO, INPUT); }

void loop() { // put your main code here, to run repeatedly:

if (digitalRead(AUTO) == LOW ) { Serial.println("Auto pressed"); vertical (); } if (digitalRead(POWER) == LOW ) { Serial.println("Power pressed"); }

}

void vertical () {

Serial.println (millis()); starttime = millis(); Serial.println("starttime"); Serial.println(starttime); Serial.println("starttime"); do { nowtime = millis(); Serial.println(nowtime); Serial.println("nowtime"); Serial.println(nowtime); } while ( (digitalRead(POWER) == HIGH ));

movetime = starttime - nowtime; Serial.println("movetime"); Serial.println(movetime); Serial.println("starttime"); Serial.println(starttime); Serial.println("nowtime"); Serial.println(nowtime);

}

nowtime-starttime is what you want.

You have it the other way around, so you'd get a negative number. But you're using an unsigned datatype, so you get a very large number instead

is there any way to search the forum

Top/right of the forum pages. What do you see ?