' this code works with the usb type basic stamp that is attached

' to the foamcore board with hacked remote for the ZML projectors

'

' basically, keys on the keyboard of the controlling computer send

' serial data to the stamp which will have the stamp execute a number

' of different effects.

'

' Basic Theory of Operation:

' the stamp used all 16 I/O pins as output.

'

' STEP ONE: The last two pins (14 AND 15)

' are wired to control a cmos switch on the stamp's protoboard which effectively

' 'push' the freeze button and the rgb1 button.  The freeze button being used

' to freeze a frame of video into a projector, and the rgb1 button being used to

' set the video input to the projector to the RGB1 port - which also has the effect

' of undoing the freeze function.  (note, if video sync is ever lost by any projector,

' even if the frame is frozen, the frozen frame is lost.

'

' STEP TWO: The first 14 pins (0 through 13)

' are wired to enable the output of the remote control to go to each of the 14

' projectors.  They are wired as you would expect with pin 0 going to projector one

' which is the one closest to the zml entry door and pin 13 going to projector 14

' which is the one closest to the accessable door that leads into the game lab.

'

' So basically you need to 'enable' or 'open the channel' to the desired projectors by

' turning their respective pin high, and then you need to 'push the freeze button'.

'

' It is pretty simple, most of the code below was a late night hack to make some

'effects that I thought would go well with my presentation.  In particular this code

' maps the 12345tgbvcxz keys to spatially correspond with the projectors in ZML.  1 is

' projector 1 and then it 'loops around' until the z key is projector 14.  The code

' starts by resetting all the projectors, and then freezes them all except for the two center

' projectors.  Then, if you hit one of the aformentioned keys, the video replicates itself

' moving from the center screen over to the left or right to the chosen screen.  If you

' hit shift-key, then that screen has it's freeze button pushed once - so you need to do

' shift-key twice if you want to 're-freeze' the video.  Finally, if you hit the 'a' key, the

' video loops around the room being frozen as it goes, except for the two center

' projectors.  If you try to figure out why I coded it the way I did, and think that

' logic, simplicity, or elegance was involved, you will be thwarted in your attempts.

'

' I would recommned that you ignore all of my code and just try writing out to the ports

' as described here.  The pause times below might be useful.

'

' mbolas november 2004

'

'

' {$STAMP BS2}

' {$PBASIC 2.5}                         ' version 2.5 required

 

'basic variables

 

c              VAR    Word ' is the changes variable

d              VAR    Word ' is another changes variable

serdata        VAR    Word

dumc           VAR    Word

dumd           VAR    Word

specialdata    VAR    Word

 

 

Initialize:

DEBUG "Init"

 

' set up pins to all be output pins

DIRS = %1111111111111111

 

'open up the channels so next command can go out to all of them

OUTS = %0011111111111111

 

'now set to rgb so the freeze is known thawed

GOSUB pushrgb

 

'freeze all of the screens

OUTS = %0011111100111111

GOSUB pushfrez

 

Main:

 

SERIN 16,$4054,1000, special, [serdata]     'number between 0 to 5192

DEBUG "serial data is", DEC serdata, CR

 

IF serdata = 49  THEN cis1

IF serdata = 50  THEN cis2

IF serdata = 51  THEN cis4

IF serdata = 52  THEN cis8

IF serdata = 53  THEN cis16

IF serdata = 54  THEN cis32

IF serdata = 121 THEN cis64

IF serdata = 104 THEN cis128

IF serdata = 110 THEN cis256

IF serdata = 98  THEN cis512

IF serdata = 118 THEN cis1024

IF serdata = 99  THEN cis2048

IF serdata = 120 THEN cis4096

IF serdata = 122 THEN cis8192

 

IF serdata = 33 THEN dis1

IF serdata = 64 THEN dis2

IF serdata = 35 THEN dis4

IF serdata = 36 THEN dis8

IF serdata = 37 THEN dis16

IF serdata = 94 THEN dis32

IF serdata = 89 THEN dis64

IF serdata = 72 THEN dis128

IF serdata = 78 THEN dis256

IF serdata = 66 THEN dis512

IF serdata = 86 THEN dis1024

IF serdata = 67 THEN dis2048

IF serdata = 88 THEN dis4096

IF serdata = 90 THEN dis8192

 

' specialdata hacked in for the

' continuous looping effect

 

IF serdata = 97 THEN specialdata = 1

IF specialdata = 1 THEN special

 

cis1: c=1

GOTO cc

cis2: c=2

GOTO cc

cis4: c=4

GOTO cc

cis8: c=8

GOTO cc

cis16: c=16

GOTO cc

cis32: c=32

GOTO cc

cis64: c=64

GOTO cc

cis128: c=128

GOTO cc

cis256: c=256

GOTO cc

cis512: c=512

GOTO cc

cis1024: c=1024

GOTO cc

cis2048: c=2048

GOTO cc

cis4096: c=4096

GOTO cc

cis8192: c=8192

GOTO cc

 

dis1: d=1

GOTO dd

dis2: d=2

GOTO dd

dis4: d=4

GOTO dd

dis8: d=8

GOTO dd

dis16: d=16

GOTO dd

dis32: d=32

GOTO dd

dis64: d=64

GOTO dd

dis128: d=128

GOTO dd

dis256: d=256

GOTO dd

dis512: d=512

GOTO dd

dis1024: d=1024

GOTO dd

dis2048: d=2048

GOTO dd

dis4096: d=4096

GOTO dd

dis8192: d=8192

GOTO dd

 

cc:

 

IF c >32 THEN GOTO ccprime

specialdata = 0

dumc = 32

GOSUB docc

dumc = 16

GOSUB docc

dumc = 8

GOSUB docc

dumc = 4

GOSUB docc

dumc = 2

GOSUB docc

dumc = 1

GOSUB docc

 

GOTO main

 

ccprime:

specialdata = 0

dumc = 256

GOSUB dodumcc

dumc = 512

GOSUB dodumcc

dumc = 1024

GOSUB dodumcc

dumc = 2048

GOSUB dodumcc

dumc = 4096

GOSUB dodumcc

dumc = 8192

GOSUB dodumcc

 

GOTO main

 

'here we pushfrez twice in a row - this effectively lets the video flow for

'a short while and then we freeze it again.

docc:

OUTS = dumc

GOSUB pushfrez

PAUSE 5

GOSUB pushfrez

PAUSE 5

IF dumc <= c THEN GOTO main

RETURN

 

dodumcc:

OUTS = dumc

GOSUB pushfrez

PAUSE 5

GOSUB pushfrez

PAUSE 5

IF dumc >= c THEN GOTO main

RETURN

 

dd:

OUTS = d

GOSUB pushfrez

PAUSE 5

specialdata = 0

GOTO main

 

END

 

' this subroutine pushes the freeze.  It has To be down For the times below for the command

' to reliably get through.  Note, this only pushes the button which acutally

' will *toggle* the image being frozen or flowing.

pushfrez:

OUT14 = 1       'fire the remote to let data in

PAUSE 80

OUT14 = 0       ' let go of the button

PAUSE 55

RETURN

 

' this subroutine pushes the RGB1 button.  Used primarily to reset and guarantee that the image is not frozen.

' 125 miliseconds is a safe length, not sure if it can go shorter.

pushrgb:

OUT15 = 1

PAUSE 125

OUT15 = 0

PAUSE 7500

RETURN

 

special:

IF specialdata <> 1  THEN GOTO main

dumc = 32

GOSUB doee

dumc = 16

GOSUB doee

dumc = 8

GOSUB doee

dumc = 4

GOSUB doee

dumc = 2

GOSUB doee

dumc = 1

GOSUB doee

dumc = 256

GOSUB doee

dumc = 512

GOSUB doee

dumc = 1024

GOSUB doee

dumc = 2048

GOSUB doee

dumc = 4096

GOSUB doee

dumc = 8192

GOSUB doee

specialdata = 1

GOTO main

 

doee:

OUTS = dumc

GOSUB pushfrez

PAUSE 5

GOSUB pushfrez

PAUSE 5

RETURN