global serialObject global myVar1, myVar2, myVar3 on startMovie clearglobals -- variables for setting up the xtra. -- Fill in your own values from the email -- that you get from the licence registrar: -- fill in your email address below (see physicalbits.com for details) programmerName = "youremail@some.com" serialnum = "xxxx-xxxx-xxxx-xxxx" -- physicalbits.com will mail you this number licenseLength = 90 -- fill in the name of your serial port below (e.g. COM1 on Windows): mySerialPort = "/dev/cu.USA19QW191P1.1" -- make a new instance of the xtra (mac OSX) openxlib the pathname & "serialXtra.osx" -- use this line instead for Windows: -- openxlib the pathname & "serialXtra.xtr" serialObject = new (xtra "SerialXtra", programmerName, serialnum, licenseLength ) -- check that it has been created correctly if objectP( serialObject ) then put serialObject else alert("Instance not valid") end if -- open the serial port: serialObject.openPort(mySerialPort) -- set the data rate, start bits, etc: serialObject.setProtocol(9600, "n", 8, 1) end on stopMovie -- dispose of the xtra and close the xtra file serialObject.closePort() set serialObject to 0 closeXlib end on exitFrame doSerial go the frame end on doSerial -- see if the port’s been opened: If serialObject.isPortOpen() then If serialObject.charsavailable() = 0 then --send a byte to ask for data SerialObject.writeChar("A") End if If SerialObject.charsAvailable() >=3 then --first byte sent by microcontroller: MyVar = SerialObject.readNumber() --next byte sent by microcontroller: MyVar2 = SerialObject.readNumber() --third one sent by microcontroller: MyVar3 = SerialObject.readNumber() end if end if end