Reading the Games Port in MSW Logo cont ...

The procedure outlined below reads the first line of the Games Port (ie data line zero with the function "InGamePort 1"). The result is displayed as a moving 'needle' simulating an analogue "meter". Buttons are used to Start, Stop and Close the procedure. The actual value read is also displayed as the label on one of the buttons.

The on-screen display appear as ...

meter.gif (3928 bytes)

The code for the procedures is:

to control
; Written by Jim Fuller October 1999
; See - http://www.southwest.com.au/<tilde>jfuller/gameport/gameport.htm
scale
make "control 1
; The variable "control" is used to start and stop input.
windowcreate "main "mywindow "Meter 10 50 50 150 []
; Creates a sub-window called "Meter"
; NOTE: You can remove this window on closing with a
; <windodelete "mywindow> comand.
; NOTE - The "[]" is a left/right square bracket. It is essential!
buttoncreate "mywindow "Start "Start 5 20 35 12 [do.until [meter1][:control = 0]]
buttoncreate "mywindow "Stop "Stop 5 50 35 12 [make "control 0]
; The lines above set up the eight individual control buttons.
buttoncreate "mywindow "Close "Close 5 120 35 10 [windowdelete "mywindow]
; This line closes the sub-window opened in the fourth line.
end

to meter1
; This is the main procedure that calls "move".
; Move actually displays the 'needle'.
; The procedure uses "ifelse" to prevent the system
; from 'hanging' with high resistances.
home
ht
make "InValue1 IngamePort 1
ifelse :InValue1 < 180 [move] [meter1]
end

to move
penpaint
buttoncreate "mywindow "InValue :InValue1 5 80 35 12 [make "control 0]
; This line creates the small button showing the
; value being read at the Games Port. (Ie the variable "InValue1")
setpencolor [255 000 000]
; Sets the pen to RED - setcolor [RED BLUE GREEN]
setpensize [2 2]
Setheading :InValue1 - 90
fd 200
wait 20
penerase
bk 200
Setheading :InValue1 - 90
buttondelete "InValue
setpensize [1 1]
end

to scale
; This procedure draws the semi-circular arc and horizontal line
; of the "meter" and writes the "0" and "180" labels.
cs
penpaint
setpencolor [0 0 0]
pu
lt 90
pu
fd 230
pd
label "0
pu
home
rt 90
pu
fd 230
pd
label "180
pu
home
pd
rt 90
arc 180 205
pu
home
pd
rt 90
fd 205
home
lt 90
fd 205
pu
home
pd
end

<- back