Joan Soler-Adillon [*] || ITP Page

Joan Soler Adillon [*]|| ITP Page

[Fall 2003] Physical Computing

Instructor: Jeff Federson

See Syllabus


Weeks nine and ten:

From stupidity to Serial Killer
When you see an image, look it right, and READ THE COMENTS!

This image was preceded by the comment: PC serial cable (facing the soldering lugs of a female connector) and I didn't really pay attention to it, so I soldered and worked with the connections as if the female connector of the image was seen from the holes.

Result: nothing worked at all, no connection between the bx and my pc.

Only when I though that maybe the drawing was wrong and tried to do it backwards I finally got some signal to the Director example.

After that, I looked again at the image and realized that it wasn't it which was backwards, it was me! Again! I really think that the last month with the midterms and the Application's class presentation have fried my brain...

After this experience, the process of getting bx24 and director married continues... (week 10 is not over)

I don't understand why, but I can make mr.Bx talk to Director but not to HyperTerm... anyway, the communication with Director is working. I got the pcomp web example of Mutly-byte serial exhanges, call and response method.

First step, get to understand what was each line of both codes exactly doing. Once I got it, apply a fourth element to be sent to Director: a switch.

After I had that done, I started to work in the Director application.

I decided to make it a shooting game: nonsense violence... THE SERIAL KILLER

This are the targets. Two potentiometers control the H and V location of the pointer (pins 13 and 14 in the BX24), and there's a switch on pin 16 as a shooting device. If the shoot gets the target, the head changes to the next untill the ghost appears. Since ghosts cannot be killed, the game is over.

The BX code is quite simple, and it's sending, when required, the two potentiometer values as bytes and the state of the switch:
Option Explicit


dim adc1Var as byte
dim adc2Var as byte
dim adc3Var as byte
dim inByte as byte
dim gotaByte as boolean
dim inputBuffer(1 To 13) As Byte
dim outputBuffer(1 To 10) As Byte
'this is the other
dim switchState as byte

 
sub main ()
 ' set up serial port:
 call defineCom3(12,11,bx1000_1000)
 call openQueue(inputBuffer, 13)
 call openQueue(outputBuffer, 10)
 call openCom(3,9600,inputBuffer, outputBuffer)

	
 do
  ' read sensors:
  adc1Var = cByte(getADC(13)\4)
  adc2Var = cByte(getADC(14)\4)
' adc3Var = cByte(getADC(15)\4)
  switchState = getpin(16)
'		debug.print "out we go"
		debug.print "the switch " & cstr(switchState)
		debug.print "pot in pin 13 = " & cstr(adc1Var)
		debug.print "pot in pin 14 = " & cstr(adc2Var)
' delay i find useful for debugging in bx
'	call delay(0.5)
		
  ' read serial data in:
  if statusQueue(inputBuffer) = true then
      call getQueue(inputBuffer, inByte, 1)

     ' if you got the message from director, send out data:
     if inByte = 65 then
       call putQueue(OutputBuffer, adc1Var, 1)
       call putQueue(OutputBuffer, adc2Var, 1)
'      call putQueue(OutputBuffer, adc3Var, 1)
	  call putQueue(OutputBuffer,switchState,1)

     end if
  end if
  loop
end sub

The greatest feature was the reinvention of the Joystick: this is what we could call the PROTOTIPE:

On the other side, in director the code going on is way more complex:


(exit frame; behavior script)

global bouncing
on exitFrame
  doSerial
  go the frame
  
end 


(comunicating with mr Bx; movie script)

global serialObject
global myVar1, myVar2
global switchState
global switchVar
global shootingSprite,displaySprite,Iam
global didUserShoot
global bouncing

--xtra "SerialXtra","js1800@nyu.edu" , "xxxx-xxxx-xxxx-xxxx",90 


on startMovie
  clearglobals
  
  --------------set variables
  displaySprite=1
  shootingSprite=3
    sprite(displaySprite).loch = 500
    sprite(displaySprite).locv = 300
    sprite(shootingSprite).loch = 50
     sprite(shootingSprite).locv = 50
  Iam=["red","orange","green","ghost"]
  bouncing=true
  
  
  -- variables for setting up the xtra.
  -- Fill in your own values from the email
  -- that you get from the licence registrar:
  
  -- fill in your email address below (see physicalbits.com for details)
  programmerName = "js1800@nyu.edu"
  serialnum  =  "YJI2-4BJF-QP2I-LPF4"   -- physicalbits.com will mail you this number
  licenseLength = 90
  
  -- fill in the name of your serial port below (e.g. COM1 on Windows):
  mySerialPort = "COM1"
  
  
  
  -- make a new instance of the xtra (mac OSX)
  --openxlib the pathname & "serialXtra.osx"
  
  -- use this line instead for Windows:
  openxlib the pathname & "serialXtra.xtr"
  
  
  serialObject =  new (xtra "SerialXtra","js1800@nyu.edu" , "YJI2-4BJF-QP2I-LPF4",90 ) 
  
  -- check that it has been created correctly     
  if objectP( serialObject ) then
    put serialObject 
  else
    alert("Instance not valid")
  end if
  
  --    open the serial port:
  serialObject.openPort(mySerialPort)
  
  
  -- set the data rate, start bits, etc:
  serialObject.setProtocol(9600, "n", 8, 1)
end

on stopMovie  
  -- dispose of the xtra and close the xtra file
  serialObject.closePort()
  set serialObject to 0
  closeXlib 
end 



on doSerial
  -- see if the port’s been opened:
  If serialObject.isPortOpen() then
    --    put "serialObject.isportopen"
    If serialObject.charsavailable() = 0 then
      --      put "serialObjectCharsavailahle is 0"
      --send a byte to ask for data
      SerialObject.writeChar("A")    
--      put "a was sent"
    End if
    
    
    If SerialObject.charsAvailable() >=3 then    
--      put "cahrsavailable>=3"
      --first byte sent by microcontroller:
      MyVar1 = SerialObject.readNumber()    
--      put Myvar1
      --next byte sent by microcontroller:
      MyVar2 = SerialObject.readNumber()    
--      put myvar2
      --third one sent by microcontroller:
      switchVar = SerialObject.readNumber()    
--      put switchState
    end if
  end if 

end 



(targetSprite; behavior script attached to the targets)

property displaySprite
property Iam
property hDir,vDir,mida,maximwidth,minimwidth
global bouncing

on startmovie me
  
end


on beginSprite me 
  
  displaySprite = 1
  Iam=["red","orange","green","ghost"]

  hDir=2
  vDir=2
  maximwidth=120
  minimwidth=30
  mida=1
  
end

on exitframe me
  
  if bouncing=true then 
    sprite(displaysprite).loch = sprite(displaysprite).loch + hDir 
    sprite(displaysprite).locv = sprite(displaysprite).locv + vDir 
    sprite(displaysprite).width = sprite(displaysprite).width + mida
    sprite(displaysprite).height = sprite(displaysprite).height + mida
    
    if sprite(displaysprite).width > maximwidth then
      mida = -mida
    else if sprite(displaysprite).width < minimwidth then
      mida = -mida
    end if
    
    if sprite(displaysprite).loch > 590 then
      hDir = -hDir
    end if
    if sprite(displaysprite).loch < 50 then
      hDir = -hDir
    end if
    if sprite(displaysprite).locv > 430 then
      vDir = -vDir
    end if
    if sprite(displaysprite).locv < 50 then
      vDir = -vDir
    end if 
  end if
  
end


(shooting; behavior script attached to the pointer)

property lastShootVarState
property ShootingSprite,targetSprite
global MyVar1,MyVar2
global displaysprite
global Iam
global switchVar
global bouncing


on beginsprite me
  clearGlobals
  shootingSprite=3
  targetSprite=1
  lastSwitchVar=switchVar
  
end

on exitFrame me

  sprite(shootingSprite).loch = Myvar1* 2.4 + 15
  sprite(shootingSprite).locv = Myvar2* 1.75 + 20
  updatestage 

  if SwitchVar = lastShootVarState then
    nothing
  else
    
    
    shoot()
    
    lastShootVarState = switchVar   
  end if

end


on shoot()  
  put "shooting"
  if sprite(shootingSprite).intersects(sprite(targetSprite)) then
    put "touche"
    touche()
  else
    nontouchepas()
  end if
end

on nontouchepas()
  puppetSound "gunfails"
end

on touche()
  put "touche"
  if sprite(displaysprite).member = member(Iam[4]) then
    
    put "all dead"
    
  else
    
    bouncing=false
    
    
    starttimer
    put "touche"
    
    puppetSound "tocat"
    

    repeat with i=1 to Iam.count-1
      if sprite(displaysprite).member = member(Iam[i]) then
        sprite(displaysprite).member = member(Iam[i+1])
        exit repeat
      end if
      
    end repeat
    bouncing=true
  end if


The only problem with this project was the inconsistence of the shooting device. I had to make it a switch from pin to ground, which as far as I know is weird, since the BX code is doing a GET PIN to send the switch state. The switch should be from 5v to pin, and then when the switch is open (there's no contact between the wires) the getpin would be 0, and 1 on the other case.

But surprisingly this setup would not work. So I had to make the switch from pin to ground. This made the shooting device go a little wild once in a while, making the gun a really dangerous weapon...

HIPOTHESIS: maybe a resistor would help.

Hipothesis tested: It seems to be better, but not 100%. Anyway, if I were to go on with this, I should get the bx to sent the shooting bit everytime the user presses the switch, one shot every time. That would involve a little change in the bx code in order to make sure it works correctly.

(the gun)

journal index

Week eleven to the end:

midi lab assignment... and preparing (thought, anxiety, panic) for the final project

journal index

Back