Go Down

Topic: ASCII to Number (Read 660 times) previous topic - next topic

mcgrath3

I am using LiveCode to work with the Arduino Uno which has an LED attached and LC is sending ascii characters to the arduino which is looking for a number. I send 125 and it is reading:
1
2
5
Not 125.

How do I parse that together again? Or how do I send what the Arduino is looking for to get a 0 -255 for an Analog LED ?

zoomkat

Some simple code you can try for capturing your number string and converting to a number.


Code: [Select]
// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

String readString;

void setup() {
Serial.begin(9600);
        Serial.println("serial test 0021"); // so I can keep track of what is loaded
        }

void loop() {

        while (Serial.available()) {
        delay(1); 
    if (Serial.available() >0) {
        char c = Serial.read();
        readString += c;}
        }
       
      if (readString.length() >0) {
      Serial.println(readString);
     
    int n;
    char carray[6]; //converting string to number
    readString.toCharArray(carray, sizeof(carray));
    n = atoi(carray);
    Serial.println(n); // print number
     
      readString="";
      }
   }
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

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!

Arduino
via Egeo 16
Torino, 10131
Italy