Wilson Director ARduino interface key scripts key scripts from wilson.arduinotemp14.dir To make this work, you would need to be sure all fields, buttons, and other objects referred to were in place in your director movie. The best approach would be to get the zipped version of the director movie which would have all that. ======== put on the movie level --===============start routines on startmovie global newflag startsensors newflag = -1 member ("start web").text = "start web" end startmovie on idle global target z = the ticks -- if z > target then -- target = z + 2*60 -- beep -- --masterweb -- aninroutine end if end --you must have Geoff Smith's SerialXtra in your Xtra directory --============================================ -- this routine checks if you have already intiialized the serial xtra -- if not, you need to initialize by setting a global variable arbitraily called port -- you will need to refer to that name in many of the other routines -- equal to the result of new (xtra "SerialXtra" "Printer Port USB") command -- note that the second parameter is the name of the port -- that you set with the keyspan control panel -- next it sets the baudrate (which is the speed of communication) -- it could be other rates (check the documentation of the xtra) -- you would call this routine from the startmove handler -- put FindPorts() -- put interface ( xtra "SerialXtra") -- **** Note this example assumes -- you have loaded Steve Wilson's Wilson.GeneralSerialIOControl -- program into Arduino board -- activate the xtra for communication with Arduino on startsensors global port, gxtra put new(xtra "SerialXtra","author@physicalbits.com","JGBR-8BDG-94JZ-DDJ2",90) into gxtra if objectP(gxtra) then --/dev/cu.usbserial-A4000PFe --/dev/cu.usbserial-3B1" --/dev/cu.usbserial-1B1 port = gxtra.OpenPort("/dev/cu.usbserial-1B1") -- arduino -- you will need to find the specific name of your port on your compter -- put FindPorts() will list them if the serialXtra is installed gxtra.SetBaudrate(9600) end if port = gxtra end --- this is general routine to read in values from Arduino -- it is used by the getdigital and getanalog buttons -- x parameter is the letter to send to Arduino --"A" for analog pin reading -- "E" for digital pin reading -- zz is the name of the field to report the results to on readard x, zz--valid line numbers are 1-8 global port z="" flag = 0 port.FlushInputBuffer() port.Writestring(x) -- write a capital whatever --port.WriteNumber(lineNo-1) -- write the line number repeat while port.CharsAvailable()<40 -- put port.CharsAvailable() q=port.readChar() z=z&q --put q if q= "$" then exit repeat end if end repeat --z = port.Readstring() -- reads result from board prepdata z,zz end -- this routine formats the incoming strings from arduino -- it puts each result on a line with a label for which pin it is -- it works slightly different with zz = digin field or anin field -- your program would then need to get the values you want to act on them -- the results do not need to be formatted as they are in this example on prepdata z,zz if zz = "digin" then -- format for digin field c = the number of chars in z -- put z repeat with n = 2 to c-1 put n&& char n of z into line (n-1) of field zz end repeat end if if zz = "anin" then -- format for digout field repeat with n = 0 to 5 tar = n*2 --put line (tar+1) of z into z3 put line (tar+2) of z into z4 put "" into char 1 of z4 -- get rid of control character put n&&z4 into line n+1 of field "anin" end repeat end if end -- activated by button "send digitial" -- assumes a field called "digout" where string is placed - eg HHLLHH on digoutroutine global port a=field("digout") a1= "D"&a port.writestring(a1) end -- activated by button "send analog" -- assumes a field called "anout" where values to be sent are placed -- one value on each line 0=255 eg 200(line1),120(line2),255(line3) on anoutroutine global port a=field("anout") a1 = numtochar(integer(line 1 of a)) a2 = numtochar(integer(line 2 of a)) a3 = numtochar(integer(line 3 of a)) a4= "B"&a1&a2&a3 port.writestring(a4) end -- activated by button "getdigital" -- assumes a field called "digin" on diginroutine global port readard ("E","digin") end -- activated by button "getanalog" -- assumes a field called "anin" on aninroutine global port readard ("A","anin") end --read stuff sent from web and respond -- the trial web page is "http://online.sfsu.edu/~netart/511tele00/index.htm" --form looks like $aa3a$se - $dis:HHHLLL from $ans:AS1:11AS2:22AS3:33 10:51:39 10/29/06 (0)------ -- html looks like
  • $aa3a$se - $dis:HHHLLL from $ans:AS1:11AS2:22AS3:33 10:51:39 10/29/06 --(0) on masterweb -- don't do it if newflag = -1 global newflag if newflag >-1 then beep if newflag = 1 then startgetweb else checkgetweb end if end if end on startgetweb global wid,newflag u = "http://online.sfsu.edu/~netart/511tele00/index.htm" wid= getNetText( u) newflag = 0 end on checkgetweb global wid, oldpage,newflag if netdone(wid)= 1 then q1 = netTextResult() --if q1 <> oldpage then member("tempweb").text = q1 beep 3 extractweb webactivate newflag = 1 oldpage =q1 --end if end if end on extractweb global id,act,dig,an1,an2,an3 z=member("tempweb").text x1= offset("$", z) x2= offset("$aa3a$se - $dis:HHHLLL from ----$ans:AS1:11AS2:22AS3:33 10:51:39 10/29/06<" ========== put on the frame script of the movie control demo section on exitFrame me global timeflag if timeflag = 1 then put the movietime of sprite(6) into field ("curmovtime") --movielights -- movie control lights ---movieposition -- analog control movie positon --moviestart end if end on movielights -- this turns digital on/off based on movie z = field ("curmovtime") if z > 623 and z < 643 then -- close up #1 put "H" into char 1 of field ("digout") digoutroutine -- turn on light 8 end if if z > 757 and z < 777 then -- end closeup put "L" into char 1 of field ("digout") digoutroutine -- turn off light 8 end if end on movieposition -- reads analog in and changes movie to position if the timer > 60*4 then -- reads only on 4 seconds aninroutine starttimer -- resets timer to 0 end if z = word 2 of line 1 of field "anin" --analog 0 z1= integer(z) set the movietime of sprite(6)=z1 -- puts movie in position end on moviestart -- reads digital in and starts and stops movie if the timer > 60*4 then -- reads only on 4 seconds diginroutine starttimer -- resets timer to 0 end if z = word 2 of line 2 of field "digin" --digin 3? put z if z = "H" then set the movierate of sprite(6)=1 -- starts movie else set the movierate of sprite(6)= 0 -- stops movie end if end ==========