rem this sample script file to be used with HMS boards with 8 or 16 outputs rem the gpio port does not set an event when a button is released. rem the ttl port causes an event when a button is released. Polling the HMS board results in the same button value untill the switch is released. rem the 'no polling option' on the HMS board has to match the conditionals (change in inputs cause the input 'byte' to be sent!) (no polling of the HMS board required) delay = 100 'number of milliseconds to wait to check board for ttl input port1 = 0 'outputs 0-7 port2 = 0 'outputs 8-15 serial_byte = false 'conditional 'if' statement so that if the event was roStreamByteEvent then have to wait until the roStreamByteEvent value is zero or video end! interruptable = false 'set this to true if want to allow interrupt of video with next press of button p=createobject("roMessagePort") gpio=createobject("roGpioControlPort") ttl=createobject("roSerialPort",1,38400) v=createobject("roVideoPlayer") gpio.SetPort(p) 'set unit to listen for gpio events ttl.SetByteEventPort(p) 'set unit to listen for byte events over 5v serial port v.SetPort(p) 'set unit to listen for video events, including end of video REM REM Array contain names of videos to play dim vlist[9] vlist[0] = "video1.mpg" vlist[1] = "video2.mpg" vlist[2] = "video3.mpg" vlist[3] = "video4.mpg" vlist[4] = "video5.mpg" vlist[5] = "video6.mpg" vlist[6] = "video7.mpg" vlist[7] = "video8.mpg" vlist[8] = "video9.mpg" REM REM Array of light outputs, matching light # with actual binary value dim lights[9] lights[0] = 0 lights[1] = 1 'output 0, or output 8 lights[2] = 2 'output 1, or output 9 lights[3] = 4 'output 2, or output 10 lights[4] = 8 'output 3 or output 11 lights[5] = 16 'output 4 or output 12 lights[6] = 32 'output 5 or output 13 lights[7] = 64 'output 6 or output 14 lights[8] = 128 'output 7 or output 15 start: v.PlayFile("attractloop.mpg") interruptable = true 'monitor the switches loop: msg = wait(delay,p) rem if both output ports (0-7 and 8-15) on the HMS board need to be set, send both port1 and port2 values rem otherwise just send the port1 value if type(msg) = "roGpioButton" and interruptable then serial_byte = false port1 = lights[msg.GetInt()+1] port2 = 0 'outputs 8-15 off ttl.SendByte(port1) 'setting output lights 0-7 to match inputs 0-7) ttl.SendByte(port2) rem interruptable = false 'no interrupt of current video if false v.PlayFile(vlist[msg.GetInt()]) elseif type(msg) = "roStreamByteEvent" and interruptable then if msg.GetInt() = 1 then serial_byte = true 'the input from the hms board has to be zero to continue polling the hms board port1 = 0 'turn off lights 0-7 port2=1 'turn on light 8 ttl.SendByte(port1) ttl.SendByte(port2) rem interruptable = false v.PlayFile(vlist[8]) 'input 8 is low (sent as val 1) rem for each value input (1,2,4,8,16,32,64,128) there can be an associated file to play rem elseif msg.GetInt() = 2 then ... 'input 9 is low (sent as val 2) rem serial_byte = true rem port1 = 0 rem port2 = 2 'turn on light 9 rem ttl.SendByte(port1) rem ttl.SendByte(port2) rem interruptable = false 'set to true if want to interrupt video in progress rem v.Playfile..... rem elseif msg.GetInt() = 4 then ... 'input 10 is low (sent as val 4) rem serial_byte = true remp port1 = 0 rem port2 = 4 'turn on light 10 rem ttl.SendByte(port1) rem ttl.SendByte(port2) rem interruptable = false 'set to true if want to interrupt video in progress rem v.Playfile..... rem elseif msg.GetInt() = 8 then ... 'input 11 is low (send as val 8) rem serial_byte = true rem port1 = 0 rem port2 = 8 'turn on light 11 rem ttl.SendByte(port1) rem ttl.SendByte(port2) rem interruptable = false 'set to true if want to interrupt video in progress rem v.Playfile..... rem elseif msg.GetInt() = 16 then ... 'input 12 is low (sent as val 16) rem serial_byte = true rem port1 = 0 rem port2 = 16 'turn on light 12 rem ttl.SendByte(port1) rem ttl.SendByte(port2) rem interruptable = false 'set to true if want to interrupt video in progress rem v.Playfile..... rem elseif msg.GetInt() = 32 then ... 'input 13 is low (sent as val 32) rem serial_byte = true rem port1 = 0 rem port2 = 32 'turn on light 13 rem ttl.SendByte(port1) rem ttl.SendByte(port2) rem v.Playfile..... rem elseif msg.GetInt() = 64 then ... 'input 14 is low (sent as val 64) rem serial_byte = true rem port1 = 0 rem port2 = 64 'turn on light 14 rem ttl.SendByte(port1) rem ttl.SendByte(port2) rem v.Playfile..... rem elseif msg.GetInt() = 128 then ... 'input 15 is low (sent as val 128) rem serial_byte = true rem port1 = 0 rem port2 = 128 'turn on light 15 rem ttl.SendByte(port1) rem ttl.SendByte(port2) rem v.Playfile..... else if type(msg) = "roVideoEvent" then if msg.GetInt() = 8 goto start endif rem add this next 'if conditional' if polling of the HMS board is being utilized. rem no need to monitor the serial byte if interruptable is false rem if serial_byte and interruptable 'serial_byte = true (valid roStreamByteEvent), otherwise set to false with 'roGpioEvent' rem While true rem msg = wait(0,p) rem if type(msg)="roStreamByteEvent" and msg.GetInt()>0 then ttl.SendByte(port1) 're-send the polling byte to the HMS board as a switch is still closed. rem if type(msg)="roStreamByteEvent" and msg.GetInt()=0 then exit while 'the switches on the HMS board was released rem if type(msg) = "roVideoEvent" and msg.GetInt() = 8 then goto start rem End While rem serial_byte = false 'the last response from the hms board was zero (inputs 8-15 all off) rem endif goto loop