Go Down

Topic: ASCII to Number (Read 586 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="";
      }
   }
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Go Up