Ok so i asked a similar question the other day, but admittedly I worded it very poorly.I want to measure the amount of time an led is on for.So imagine that i have 2 arduinos and one is simply turning an led on and off for random amounts of time, and i have a second arduino, i want to use this second arduino to measure the length of each pulse and then print this value to serial monitor
Any help would be greatly appreciated, Thanks in advance!
UKHeliBob:
Save the value of millis() when the LED turns on.
Save the value of millis() when the LED turns off
The difference is the pulse length
Are the two Arduinos connected in any way ?
Do you actually need to use two Arduinos ?
No I dont need to use 2, i just need to be able to measure the length of time an led is on for.
So how would i go about using millis() to do this then?
When digitalwrite is high you'll need a variable to attach the current millis value to and same for when digitalwrite is low. Then subtract those two values.
The line right after loop is part of the problem. You need time = Millis
You listed time in the globals but didn't use it.
Also use Unsigned Long. Long lets you use negative numbers and we don't need that to measure time.
I suspect that measuring how long an LED was on is not the actual project... I could be wrong though.
posting the true and full code using code tags would be extremely beneficial.