Pages: [1]   Go Down
Author Topic: ASCII to Number  (Read 440 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8922
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Code:
// 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="";
      }
   }
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Pages: [1]   Go Up
Jump to: