homewiring diagramsbasic stamp II program

cast & score windows:

download director movie: directorStamp.sit

movie script:

global gSerialPort

on startMovie
  
if the platform contains "Macintosh" then
    
openxlib "SerialXtra"
  
else
    
openxlib "SerialXtra.x32"
  
end if
  
put interface(xtra "Serialxtra") -- list interface in message window
  portList = findPorts()
  
put portList -- list available ports
  
put new(xtra "SerialXtra",("Keyspan USB DB9")) into gSerialPort
  
put SetBaudRate(gSerialPort,9600)
end

on stopMovie
  
set gSerialPort to 0
  
closexlib
  
put "Closed"
end

on enterframe
  
if objectp(gSerialPort)then
    gCharsWaiting = CharsAvailable(gSerialPort)
    
if CharsAvailable(gSerialPort)>1 then
      gInData = ReadString(gSerialPort)
      
put gInData -- print out incoming data
      
if gInData = "Switch ON" then
        
sendSprite(3,#makeVisible)
      
else if gInData = "Switch OFF" then
        
sendSprite(3,#makeInvisible)
      
end if
    
end if
  
end if
end

depressed button sprite behavior:

global gSerialPort

on beginSprite me
  
sprite(me.spriteNum).blend = 0 -- hide depressed button image
end

on mouseDown me
  gMouseDown =
TRUE
  
sprite(me.spriteNum).blend = 100 -- display depressed button image
  myString =
"1" & RETURN
  writeString(gSerialPort,myString)
-- send a "1" to BSII to turn light on
end

on mouseUp me
  gMouseDown =
FALSE
  
sprite(me.spriteNum).blend = 0 -- hide depressed button image
  myString =
"0" & RETURN
  writeString(gSerialPort,myString)
-- send a "0" to BSII to turn light off
end

lamp hilight sprite behavior:

on beginSprite me
  
sprite(me.spriteNum).blend = 0 -- hide lamp hilight image
end

on makeVisible me -- sent from movie script
  
sprite(me.spriteNum).blend = 100 -- display lamp hilight image
end

on makeInvisible me -- sent from movie script
  
sprite(me.spriteNum).blend = 0 -- hide lamp hilight image
end

frame script: (behavior)

on exitFrame me
  
go to the frame
end

homewiring diagramsbasic stamp II program