Go Down

Topic: Moving analog data over serial (Read 3635 times) previous topic - next topic


Code: [Select]
void output64 ()
  if (valuecmd > 637)

Can I recommend you revise your binary arithmetic?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.


The example I was using is from the web site.



Yep looks like crap code in that link.

Tom Carpenter

Jan 07, 2013, 11:22 pm Last Edit: Jan 07, 2013, 11:24 pm by Tom Carpenter Reason: 1
It isn't partuclarly crap. "parseInt()" sits there trying to read in values from the Serial port until it either times out (and returns 0), or another character arrives in and it sits there trying to read the next. That means that it doesn't need for Serial.available() to be any more than 1 when you first call it for it to work.

Granted the implementation could be improved, for example, if you send "12-34" it will detect it as -1234, and if it takes too long for the 2nd, 3rd, and so on characters to arrive after each other it will just give up and return.
Also that example doesn't account for the fact that you should wait until Serial.available()>0 in between each of the calls to parseInt().


Jan 08, 2013, 02:36 am Last Edit: Jan 08, 2013, 02:38 am by retrolefty Reason: 1

Exactly because either you are missunderstanding it or it is wrong.
Serial data takes a long time to arrive, just because one byte has arrived does not mean that all the bytes have arrived. FACT.

LOL, otherwise they wouldn't be allowed to call it serial data as it would be a violation of truth in advertising. Not unlike the fundamental difference between a serial killer and a mass killer, unless you are a victim where the difference is somewhat moot.



I found the binary math problem later. Doesn't help the speed any but did fix the logic.

Go Up