-- Version 1.2 October 1998 -- Do not delete! Movie Script! Nothing will work!! -- Director for Macintosh EZ I/O movie script -- =========================================================================== -- Version 1.2 changes -- added example scripts for various operations -- =========================================================================== -- Version 1.1 changes -- scripts for readLine, readPort, and a2d now check for arrival of single -- character at the serial port, thus eliminating a previous source of errors -- =========================================================================== -- © 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! -- modem port recommended; otherwise, turn off appleTalk on printer port on startMovie global port -- init modem port put SerialPort(mNew, 1) into port -- "0" selects modem port, "1" selects printer port -- if you decided to use the printer port, make sure AppleTalk is off port(mconfigChan, 0, 19456) -- sets output driver to 57600 baud, 1.0 stop bits, no parity bit port(mconfigChan, 1, 19456) -- sets input driver to 57600 baud, 1.0 stop bits, no parity bit end -- =========================================================================== -- "numtochar()" is used often: it changes a number into a character, -- which is a convenient way to represent a number between 0 and 255, -- for transmitting it to the board -- =========================================================================== -- 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 the receive buffer put numtochar((lineNo-1)) into lineNo -- internally, the chip starts numbering lines at zero port(mWriteString, "A" & lineNo) -- sends command to board repeat while (port(mReadCount) <>1) end repeat-- this causes the program to wait for serial transmission to complete return port(mReadChar) -- returns result from board end -- =========================================================================== -- writePort will cause a pattern of ons and offs on lines Digital Out 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 put numtochar(state) into state port(mWriteString, "W" & state) end -- ============================================================================= -- writeLine turns a single line on or off, "1" being "on," "0" being "off" -- EZ I/O offers ten lines of digital output on writeLine lineNo, onOff -- valid line numbers are 1 through 10 global port put numtochar((lineNo-1)) into lineNo -- internally, the chip starts numbering lines at zero put numtochar(onOff) into onOff port(mWriteString, "w" & lineNo & onOff) end -- =========================================================================== -- readLine returns a ¯ or 1 to indicate the state of a single line, -- with "1" being "high" and "0" being "low" -- the default state, when a line has nothing switched, is "1" -- (see instructions for using digital input) on readLine lineNo -- valid line numbers are 1 through 10 global port port(mReadFlush) -- this clears out the receive buffer put numtochar((lineNo-1)) into lineNo port(mWriteString, "r" & lineNo) repeat while (port(mReadCount) <>1) end repeat-- this causes the program to wait for serial transmission to complete return port(mReadChar) -- returns result from board end -- =========================================================================== -- readPort returns a value between 0 and 255 for the 8-line port -- comprised of lines Digital Input 1 through 8 on the board -- the default state, when no lines are switched, is "255" -- (see instructions for using digital input) on readPort global port port(mReadFlush) -- this clears out the receive buffer port(mWriteString, "R") repeat while (port(mReadCount) <>1) end repeat-- this causes the program to wait for serial transmission to complete return port(mReadChar) -- returns result from board 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 put numtochar(lineNo) into lineNo -- 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 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 put numtochar(hibite) into hibite put numtochar(lobite) into lobite port(mWriteString, "P" & lineNo & hiBite & loBite) end -- =========================================================================== -- this frees up the serial link from the desktop computer before quitting Director on stopMovie global port port(mDispose) end -- ===========================================================================