week 10

Serial 2

 

 

In order to get values on the hyper terminar I tried to develop last week's code. And I use again the syntax, "call putQueueStr(outputBuffer, chr(13) & chr(10))" to got values arrangedly and clearly using ASCII code.

dim outputBuffer(1 To 45) as byte
dim inputBuffer(1 To 13) as byte

dim potVar as integer
dim FSRvar as integer
dim photocellVar as integer


Sub main()
do
call delay(0.5) ' start program with a half-second delay


call openQueue(outputBuffer, 45)
call openQueue(inputBuffer, 13)
call defineCom3(11,12,bx1000_1000)
call openCom(3, 9600, inputBuffer, outputBuffer)

FSRvar = getADC(13)
potVar = getADC(14)
photocellVar = getADC(15)

'debug.print "FSRvar = " ; cstr(FSRVar)
'debug.print "potVar = " ; cstr(potVar)
'debug.print "photocellVar = " ; cstr(photocellVar)

'myString1 = "the FSR states: " & chr(cstr(FSRVar)
'myString2 = "the potentiometer states: " & chr(cstr(potVar)
'myString3 = "the photocell states: " & chr(cstr(photocellVar)

'call putQueueStr(outputBuffer, myString1)
'' Append carriage return and line feed
'call putQueueStr(outputBuffer, chr(13) & chr(10))

'call putQueueStr(outputBuffer, myString2)
'' Append carriage return and line feed
'call putQueueStr(outputBuffer, chr(13) & chr(10))

'call putQueueStr(outputBuffer, myString3)
'' Append carriage return and line feed
'call putQueueStr(outputBuffer, chr(13) & chr(10))

call putQueue(outputBuffer, FSRvar, 1)
call putQueue(outputBuffer, potVar, 1)
call putQueue(outputBuffer, photocellVar, 1)

loop

End Sub

--------------------------------------------------------------------------
Test Note :

photocell value ranges from 30(hand on)- 750(hand off)
photentiometer value 0-1023
FSR range 0-708

--------------------------------------------------------------------------

For this week's assignment, I used a potetiometer, a FSR and a photocell. And in Director I want ed to make a beer glass and a beer bottle each of which was interactive with the above sensors. But I could understand the meaning that the most difficult part in Pcomp is making a smooth interaction by programming. Really it was hard to me to get the things which were interactive each other. Actually I wanted to make a program that if users touch a FSR, then bottle is poring beer into cup and if users turn potentiometer , then the height of beer in the glass increases or decreases according to the values. But the tricky part was controlling the values with potentiometer and using different values from diverse sensors simultaneously, because all values were connected together, so I ccould't control them step by step at each time when I want to use. For example, although the beer bottle increases the height in glass at first, next part code affect s the height of beer almost simutaneously. And because the present range of potentiometer also affects the values, it also hard to control. So I finally gave up making the objects as I planned. But it was good to know the fact again that programming is hard! Especailly making smooth actions through programming!!

BX code

dim outputBuffer(1 To 45) as byte
dim inputBuffer(1 To 13) as byte

dim potVar as integer
dim FSRvar as integer
dim photocellVar as integer

Sub main()
do
call delay(0.5) ' start program with a half-second delay


call openQueue(outputBuffer, 45)
call openQueue(inputBuffer, 13)
call defineCom3(11,12,bx1000_1000)
call openCom(3, 9600, inputBuffer, outputBuffer)


FSRvar = getADC(13) '\ 4 + 3
potVar = getADC(14)
photocellVar = getADC(15)

debug.print "FSRvar = " ; cstr(FSRVar)
debug.print "potVar = " ; cstr(potVar)
debug.print "photocellVar = " ; cstr(photocellVar)

call putQueue(outputBuffer, FSRvar, 1)
call putQueue(outputBuffer, potVar, 1)
call putQueue(outputBuffer, photocellVar, 1)

loop


---------------------------------------------------------------------------

director code

-------Movie scripts---------------------------------------------------------------------------

global gSerialPort, gCupState, potstatus, counter

on startMovie
openxlib "SerialXtra"
gSerialPort = new( xtra "SerialXtra", "COM1" ) -- put new(xtra "serialXtra", "Printer") into gSerialPort
gSerialPort.SetProtocol(9600, "n",8,1) -- setProtocol(gSerialPort, 9600, "n", 8, 1)
gSerialPort.readString()
gSerialPort.writeString("Z")
flushInputBuffer(gSerialPort)
--initSerial()

bottle = sprite(10)
beer = sprite(8)
beer.top = 300
sprite(10).blend = 100
sprite(12) .blend = 0
gCupState = #empty

member("FSRvar").text = "FSRvar "
member("potVar").text = "potentiometer "
member("photocellVar").text = "photocellVar "
end


--on initSerial
-- if the platform contains "macintosh" then
-- openxlib "SerialXtra"
-- else
-- openxlib "SerialXtra.x32"
-- end if
--
-- -- -- with a Belkin USB adapter, the serial port's ID is "Prinver"
-- -- -- you can get all the available names with FindPorts()
--
-- gSerialPort = new( xtra "SerialXtra", "COM1" )
-- -- put new(xtra "serialXtra", "Printer") into gSerialPort
-- gSerialPort.SetProtocol(9600, "n",8,1)
-- -- setProtocol(gSerialPort, 9600, "n", 8, 1)
-- -- flushInputBuffer(gSerialPort)
--end


on stopMovie
gSerialPort=0 --- set gSerialPort to 0
closeXLib
end


on checkserial
if objectP(gSerialPort) then -- if this is a valid object
if gSerialPort.CharsAvailable() > 2 then -- if there is something waiting to read
--read them in the same order that you sent them in the serout statement in the chip
FSRvar = gSerialPort.readNumber() --read FSR value : FSRvar = getADC(13) \ 2 --'\ 4
potVar = gSerialPort.readNumber() --read potentiometer : potVar = getADC(14) \ 4
photocellVar = gSerialPort.readNumber() --read photocellVar : photocellVar= getADC(15)

member("FSRvar").text = "FSRvar : " & string(FSRvar)
member("potVar").text = "potentiometer : " & string(potVar)
member("photocellVar").text =" photocellVar : " & string(photocellVar)

bottle = sprite(10)
beer = sprite(8)


if string(FSRvar) = 0 then -- if FSR id touched then
sprite(10).blend = 0
sprite(12) .blend = 100
gCupState = #full
beer.top = 150

else if string(FSRvar) > 0 then
sprite(10).blend = 100
sprite(12) .blend = 0
end if

if string(photocellVar) < 30 then
beer.top = 230 - (80/255) * string(potVar)
end if

end if
end if
end

------------ Frame Scripts-------------------------------------------------------------------

on exitFrame
checkserial
go the frame
end


 

 

Journal Index