-- Do not delete this Movie Script! Nothing will work!! -- Director for Windows EZ I/O script -- =============================================================================== -- Copyright 1997, The Regents of the University of Michigan. All rights reserved. -- Developed at the University of Michigan School of Art and Design -- by Michael Rodemer and Ed Bennett -- =============================================================================== -- =============================================================================== -- the following gets Director ready to do serial communication with the microcontroller -- on the interface board. It MUST be called before any of the other scripts associated -- with the board will work! -- Also, you must have commport.dll in the same folder as your movie! -- =============================================================================== on startMovie global port -- init comm port -- Reminder: you must have commport.dll in the same folder as your movie! openXlib "commport" if port=Void then put CommPort(mNew, "Com1", 32, 32) into port port(mSetUp, 57600, 10, 0)-- sets port to 57600 baud, 1.0 stop bits, no parity bit end if end -- =============================================================================== -- A2D will read a voltage and return its value, -- expressed as a number between 0 and 255 on A2D lineNo --valid line numbers are 1-8 global port port(mReadFlush) -- this clears out anything left in the receive buffer port(mWriteChar, 65) -- write a capital "A" port(mWriteChar, (lineNo-1)) -- write the line number -- internally, the chip starts numbering lines at 0 port(mReadCount) -- this is apprently needed to slow down the port enough to prevent errors -- namely, the same result coming back twice in spite of changed lineNo or voltage value return port(mReadChar) -- reads result from board end -- =============================================================================== -- writePort will cause a pattern of ons and offs on digital output lines 1 through 8 on the board -- depending on the value of the variable "state" on writePort state -- valid values for state are 0-255 global port port(mWriteChar, 87) -- write a capital "W" port(mWriteChar, state) -- write the state end -- =============================================================================== -- writeLine turns a single line on or off, "1" being "on," "0" being "off" on writeLine lineNo, onOff -- valid line numbers are 1 through 10 global port port(mWriteFlush) -- this clears out the transmit buffer port(mWriteChar, 119) -- write a small "w" port(mWriteChar, (lineNo-1)) -- write the line number -- internally, the chip starts numbering lines at 0 port(mWriteChar, onOff) -- write zero or one checkErr() end -- =============================================================================== -- readLine returns a 0 or 1 to indicate the state of a single line, -- with "1" being "high" and "0" being "low" on readLine lineNo -- valid line numbers are 1 through 10 global port port(mWriteFlush) -- this clears out the transmit buffer port(mReadFlush) -- this clears out anything left in the receive buffer port(mWriteChar, 114) -- write a small "r" port(mWriteChar, (lineNo-1)) -- write the line number port(mReadCount) -- this is apprently needed to slow down the port enough to prevent errors return port(mReadChar) -- return state end -- =============================================================================== -- readPort returns a value between 0 and 255 for the 8-line port -- comprised of digital input lines 1 through 8 on the board on readPort global port port(mWriteFlush) -- this clears out the transmit buffer port(mReadFlush) -- this clears out anything left in the receive buffer port(mWriteChar, 82) port(mReadCount) -- this is apprently needed to slow down the port enough to prevent errors return port(mReadChar) -- return state end -- =============================================================================== -- PWM turns a line on and off rapidly (more than 18,000 times a second), -- varying the ratio of the time the line is off to the time it is on. -- Valid input values are from 0 (always off) to 1023 (always on) on PWM lineNo, onTime -- valid line numbers are 1 or 2 global port -- the following code makes two 8-bit numbers -- out of the 10-bit number (0-1023) passed to PWM as an argument, -- passing two characters to the board one after the other port(mWriteFlush) -- this clears out the transmit buffer put 0 into temp if (onTime-512>=0) then put (temp+2) into temp put (onTime-512) into onTime end if if (onTime-256>=0) then put (temp+1) into temp put (onTime-256) into onTime end if put temp into hiBite put onTime into loBite port(mwriteChar, 80) port(mwriteChar, lineNo) port(mwriteChar, hiBite) port(mwriteChar, loBite) end -- =============================================================================== -- this frees up the serial link from the desktop computer before quitting Director on shutDown global port port(mDispose) end