How to send a number as a number or How to rule an LED

Thomas McGrath III 3mcgrath at
Fri Feb 4 11:22:28 EST 2011

I am having a problem communicating with an LED. (Never thought I'd hear myself say that!)

I have code in LC in a slider:
-- We are open driver ... for text update
on mouseUp
    put the thumbPosition of me into tValue
end mouseUp
on doUpdate tValue
    put gThePort into thePort -- global port "/dev/cu.usbmodem1a21"
    read from file thePort until empty -- clear the buffer
    put it into field "Data" -- just to see what garbage is left over - not needed
    wait 30
    write tValue to file thePort -- Vaule is 0 -255 as per the Analog specs of a PWM on the Arduino Uno for an LED
    read from file thePort until empty -- Arduino is set to send back the data received this is so I can see it
    put it after field "Data"
    if the result is not empty then put the result into field "Results" -- gives us our eof
end doUpdate

I send out a 125 but I get back three lines:
but the analogWrite is looking for 125

void loop() {
  // check if data has been sent from the computer:
  if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255):
    char received =;
    // set the brightness of the LED:
    analogWrite(ledPin, received);

If I change the Serial.println to Serial.println(received, BYTE); I still get:
But if I change it to Serial.println(received, DEC); I get these results:

So How do I send a number as a number and not as single digits?

-- Tom McGrath III
3mcgrath at

More information about the Use-livecode mailing list