Digital and Analog I/O

This AeroScript program reads and writes different types of I/O.

// Digital and Analog I/O Example:
// Demonstrates setting and getting digital and analog inputs and output.

program

	var $axis as axis = X
	var $analogVoltage as real
	var $analogInputNum as integer = 0
	var $analogOutputNum as integer = 0
	var $digitalState as integer
	var $digitalInputNum as integer = 0
	var $digitalOutputNum as integer = 0

	// Read the voltage from an analog input.
	$analogVoltage = AnalogInputGet($axis, $analogInputNum)

	// Set the measured voltage to an analog output channel.
	AnalogOutputSet($axis, $analogOutputNum, $analogVoltage)

	// Wait 100 milliseconds for the setting to take effect.
	Dwell(0.1)

	// Read the voltage that was written to the analog output.
	$analogVoltage = AnalogOutputGet($axis, $analogOutputNum)

	// Display the analog voltage in Automation1 Studio.
	AppMessageDisplay("Analog Value = " + RealToString($analogVoltage))

	// Read the state of a digital input.
	$digitalState = DigitalInputGet($axis, $digitalInputNum)

	// Write the state to a digital output.
	DigitalOutputSet($axis, $digitalOutputNum, $digitalState)

	// Wait 100 milliseconds for the setting to take effect.
	Dwell(0.1)

	// Read back the state that had been written to the digital output.
	$digitalState = DigitalOutputGet($axis, $digitalOutputNum)

	// Display the digital value in Automation1 Studio.
	AppMessageDisplay("Digital Value = " + IntegerToString($digitalState))

end