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

Thomas McGrath III 3mcgrath at comcast.net
Fri Feb 4 10:22:28 CST 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
    doUpdate(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:
1
2
5
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 = Serial.read();
   
    // set the brightness of the LED:
    analogWrite(ledPin, received);
    Serial.println(received);
  }
}

If I change the Serial.println to Serial.println(received, BYTE); I still get:
1
2
5
But if I change it to Serial.println(received, DEC); I get these results:
49
50
53

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


-- Tom McGrath III
http://lazyriver.on-rev.com
3mcgrath at comcast.net




More information about the use-livecode mailing list