Go Down

Topic: Problem with color sensor (Read 1 time) previous topic - next topic

AWOL

#5
Oct 06, 2012, 09:18 pm Last Edit: Oct 06, 2012, 09:29 pm by AWOL Reason: 1
Look at your code
Is there a single character in the serial receive buffer?
Yes, so read all eighteen of them.

Does that seem like a sensible thing to do?

Some useful reading:
http://arduino.cc/en/Serial/Available    

Hint: you're not the first person to make this mistake.
"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.

Nantonos

#6
Oct 06, 2012, 09:31 pm Last Edit: Oct 06, 2012, 09:34 pm by Nantonos Reason: 1

Usual problem - check to see if there's at least one character available to read, then go ahead and read all 18 of them.


I agree that is a problem with the code as posted.


Also, array indices usually begin at zero.


They do, but oddly, part of the code (the read loop) is 1-based while another part (the parsing) is correctly 0-based.  As an example, the first bit of actual information is the fourth character, "Red Value Hundreds Character ASCII" and the code correctly accesses this fourth item as
Code: [Select]
(color[3]-'0')*100)

AWOL

Quote
help on how to get this working fast.
At 9600 it is never going to be particularly fast.

"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.

Go Up