Go Down

Topic: Timer Issue (Read 1 time) previous topic - next topic

skydazz2000

I have switch is a line connected to Digital pins 1,2,3,4,5 . When pins 1 connects, I need a timer to start. as the rest connect i need it to mark the time in the console output of each one and End on the timer on connection to pin 5. ex



Code: [Select]
START:
0.00
1.43
2.12
2.94
3.89
END



Also is there a way to Save the data to a log (.txt or whatever) If not its fine but I need to record results.

(This is for a school project) THANKS!

PaulS

Quote
When pins 1 connects
Pin 1 should not be used. That is the hardware serial pin.

Pin n should be connected at all times. Hot-swapping components while the Arduino is running is not a good idea.

If you mean "When pin 1 reads pressed...", then look at the state change detection example to see how to determine that a switch has become pressed (or released).
The art of getting good answers lies in asking good questions.

groundFungus

And look up the millis() and micros() functions to see how to record the times.  timing tutorial

Srijal97

You cant use pin1 when using Serial(console output, this pin flashes high and low to send data via USB to the computer) as PaulS said, better not use pin2 as well(this is used to recieve signals from the USB), you have other options.

millis() is an Arduino function which "returns" the time for which the current program is running in the Arduino  in milliseconds(i.e. it is 0 every time the Arduino resets).

So you can connect 5 switches to 5 digital pins of the Arduino, set them as INPUT and do the following:
IF switch1 is pressed ==> switch1time = millis(), print 0
IF switch2 is pressed ==> switch2time = millis() - switch1time, print switch2time
IF switch3 is pressed ==> switch3time = millis() - switch2time, print switch3time
and so on...

or you can use 1 single switch connected to a single digital pin and using a counter in the program, count the number of presses, and print the respective timings.

To save the data in a text file you will have to add an SD card module(these are pretty cheap) to save the text file in it: https://www.arduino.cc/en/Reference/SD



skydazz2000

And i was using pin 1 as an example. I have no idea about the lanuguage yet but I plan too. Thanks for the help.

Go Up