The setup_RCX() function
This function is called once every time the script is started and is required to initialize the RCX:
sub setup_RCX {
my $sensor = shift;
my $rcx = Win32::OLE->new('SPIRIT.SpiritCtrl.1');
$Win32::OLE::Warn = 0;
$rcx->{ComPortNo} = 1;
$rcx->{InitComm};
$rcx->SetSensorType($sensor, 3);
$rcx->SetSensorMode($sensor, 2);
return $rcx;
}
A Win32::OLE object representing the RCX’s ActiveX
control Spirit is instantiated. A Win32::OLE
function is used to suppress warnings, and the RCX is initialized
by setting the COM port to COM1 for serial communications. The sensor type and mode are set for the light sensor
attached to the connector identified by the value passed into the
$sensor variable.
Table 9-2 shows us that sensor type 3 represents
Light, and sensor mode 2 specifies a
Transitional measurement mode,
the upshot of which is that the values returned on a poll are all within
a certain restricted range, which makes it easier to decide whether there’s any coffee in the pot.
We return the Win32::OLE RCX object to be used
elsewhere in the script for calibration and polling.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access