Go Down

Topic: Using millis() to get elapsed time (Read 16691 times) previous topic - next topic


I think it is only a 4 digit integer number that i am sending, Well here is the code,

Code: [Select]
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.
The art of getting good answers lies in asking good questions.


Oct 03, 2012, 02:38 pm Last Edit: Oct 07, 2012, 11:58 pm by ofey Reason: 1

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


I have also included a Fritzing schematic.


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

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131