Pages: 1 [2]   Go Down
Author Topic: Using millis() to get elapsed time  (Read 7340 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49291
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I think it is only a 4 digit integer number that i am sending, Well here is the code,
Code:
   Serial.println(elapsedTime);
The print()/println() methods convert the value to a string. Suppose that millis() returns a value of 873. You are then sending '8', '7', '3', <CR>, <LN> to the serial port.

You are then reading one character at a time, '8', '7', '3', <CR>, and <LF>, and assuming that you are getting an integer value ('8' != 8), which is not the case.

The Serial class in Processing has a bufferUntil() method, where you can tell Processing to call serialEvent() only when the <CR>, for instance, arrives.

In the serialEvent() method, you can then use the readUntil() method to get all the data (as a string) that has arrived ("873") up to the specified character (<CR>). Then, int() will convert that string to an int.
Logged

Dublin, Ireland
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I am trying to solve this on the Processing forum. Here is a link in case it is of any interest to anyone.

http://forum.processing.org/topic/passing-a-variable-from-ardunio-to-processing

I have also included a Fritzing schematic.

Thanks,

Shane

* Photogate.fzz (3.35 KB - downloaded 24 times.)
« Last Edit: October 07, 2012, 04:58:45 pm by ofey » Logged

Those who say it can't be done are usually interrupted by others doing it.

Pages: 1 [2]   Go Up
Jump to: