The analogue interface 9
Using the analogue interface from BASIC
The four analogue voltages being read by the Electron are assigned 'channel numbers' in the
range 1 to 4: to read the voltage on a channel, use the BASIC function
ADVAL
(minimum
abbreviation
AD
.,
token = &96). For example
horizontal = ADVAL(1) : vertical = ADVAL(2)
The variables
horizontal
and vertical will now contain integers in the range 0 to
65280,
proportional to the voltages measured on channels 1 and
2,
with V being read as approximately
0 and 1.8V as approximately
65280.
The number returned by
ADVAL
increases by steps of
256
rather than by 1 (ie 0,
256, 512 . . . 65280),
to allow for future expansion in the resolution of the
conversion process.
To determine whether the fire buttons on the paddles/joysticks are being pressed, use
ADVAL
with a channel number of 0, for example
buttons = ADVAL(0) AND 3
The value of the variable
but
t
on
s then tells you which buttons are being pressed as follows:
buttons
= 0 means no buttons are being pressed
buttons
= 1 means that push button 0 is being pressed
buttons
= 2 means that push button 1 is being pressed
buttons
=
3
means both push buttons are being pressed
Each analogue input is sampled in turn and converted to the digital result returned by
ADVAL
,
in
order of decreasing channel number. The conversion process takes 10mS ec (ie one hundredth
of a second) per active channel, so with all four channels operating, there will be a delay of
40mSec between changes in the readings. To reduce this delay, you should turn off channels
you are not using, with the
*FX16
command, as follows:
*FX16,0
turns all the analogue channels off
*FX16,1
turns
channel 1 on and channels 2 to 4 off
*FX16,2
turns channels 1 and 2 on and channels
3
and 4 off
*FX16,3
turns channels 1 to
3
on and channel 4 off
*FX16,4
turns all four channels on
Summary of Contents for PLUS 1
Page 1: ......
Page 2: ......
Page 3: ...The Electron Plus 1 User Guide Part no 419100 Issue no 1 Date March 1984 ...
Page 11: ...Setting up 5 ...
Page 29: ...Notes ...
Page 30: ......