Intro Phys Comp | Journal Entry 10 | November 22 or so, 2001

Serial Communication and Director

So I thought that it would be fun to make a little ball roam around the Director stage in response to input from two photocells, one controlling the x coordinate and one controlling the y. The ball would bounce off various obstacles and generally behave as if it were running through a maze. Then the BX would turn on a little piezo buzzer if the ball hit an obstacle. This did not happen at all. But at least I tried to write the code.

STUFF I LEARNED
The project worked, but only very occasionally. The errors made no sense at all, because the project had worked the first night I tested it. Yet the next night, sometimes I could send serial info to Director, sometimes not. This happened because I had accidentally left HyperTerm open, so that the computer was getting confused over which program (Director or HyperTerm) should be receiving the serial data.

BX CODE


'----------------------------------------------
'BX24 Serial to Director- my variation on Jen's code

dim outputBuffer(1 To 30) as byte
dim inputBuffer(1 To 30) as byte
'dim getlight as integer 
dim photo1 as integer
dim photo2 as integer
dim color as byte
dim out as byte
dim serialOUTpin as byte
dim serialINpin as byte
dim buzzer as byte

sub main()

	serialOUTpin = 12
	serialINpin = 11

	' open the input and output buffers:
	call openQueue(outputBuffer, 30)
	call openQueue(inputBuffer, 30)

	' define which pins we'll use for serial in and out:
	call defineCom3(serialINpin, serialOUTpin, bx1000_1000)
	call openCom(3, 9600, inputBuffer, outputBuffer)

	call putQueueStr(outputBuffer, chr(12))	'clears the screen

	do
		tune = getADC(19) \ 5  + 2 'a range of 0 to 255- must be a byte
		light = getADC(13) \ 4 + 2 'a range is 0 - 255 - must be a byte
		
		'I add 2 here to make sure that I never recieve anything close to a 1 value
		'as I need 1 to send to director to start my sequence.
		photo1String = cstr(photo1)
		photo2String = cstr(photo2)
		'call putQueueStr(outputBuffer, photo1String)
		'call putQueueStr(outputBuffer, chr(10) & chr(13))
		'call putQueueStr(outputBuffer, photo2String)
		'call putQueueStr(outputBuffer, chr(10) & chr(13))

		out = 1 'director knows to start sequence when 1 is recieved.
		call putQueue(outputBuffer, out, 1)' tell director to GET READY
		call putQueue(outputBuffer, photo1, 1) 'send LIGHT value (photocell)
		call putQueue(outputBuffer, photo2, 1) 'send Tune value (pot)
		call getQueue(inputBuffer, buzzer, 1) 'receive data from director
		
		if (buzzer = 255) then
			call putPin(15, 1)
		else
			call putPin(15, 0)
		end if
		
	loop
End Sub

DIRECTOR MOVIE