Go Down

Topic: Difficulty- Serial Read/Serial Print (Read 1 time) previous topic - next topic

Korman

Sorry for the sarcasm, but sometimes it's just the small joys of life that makes one go on and reply. It's nothing personal, it was just a too nice opportunity to let pass up unused. If the stuff above wasn't detailed enough, feel free to ask again - for more abuse and solutions.

Korman

sxdemon

well I did made some progress.
Same problem, but was able to finally get a string.

Korman

#7
Oct 13, 2010, 12:53 am Last Edit: Oct 13, 2010, 06:18 am by Korman Reason: 1
Here's something that could work - I'm just to lazy to test it out. It considers the first non-digit character to be the end of the number.

Code: [Select]

void loop() {
   static int readval = 0;
   static int readstatus = 0;

   if (Serial.available() > 0) {
        char c = Serial.read();
        if (isdigit (c)) {
            // We have a digit!
            readval = readval * 10 + (c - '0');
            // Remember that we have at least one good digit.
            readstatus = 1;
        }
        else if (readstatus) {
            // We got something else. Reading the number is over.

            // Process it
            if ([glow]readval > bla bla bla[/glow]) { [glow]....[/glow] }

                // Reset read status and value for next number
                readstatus = 0;
                readval = 0;
        }
   }
}


Korman

sxdemon

#8
Oct 13, 2010, 01:09 am Last Edit: Oct 13, 2010, 01:10 am by kraig Reason: 1
:-/ Thats exactly what I was looking for since yesterday.
I tried some methods with  do/while and if, but I always ended up with a little bit of complication.


I see you edited your post.

Korman

#9
Oct 13, 2010, 01:14 am Last Edit: Oct 13, 2010, 01:14 am by Korman Reason: 1
Just make sure you copy the current version, I fixed a few little bugs.

Korman

Go Up