Setting digital outputs, Example code 9.1 – Wavetronix Click 500 (programmable controller) (CLK-500) - Developer Guide User Manual
Page 99
98
CHAPTER 9 • DIGITAL INPUT/OUTPUT
Input Type
#define directive and associated integer value
Low Level AC
AC_ON == 1; AC_OFF == 0
Contact Closure
CONTACT_OPEN == 0; CONTACT_CLOSED == 1
DC
DC_ABOVE_THRESHOLD == 1; DC_BELOW_THRESHOLD == 0
VCC/Supply Voltage Monitor
VCC_OK == 1 (> supply threshold); VCC_LOW == 0
Table 9.1 – Input Type
ClickDioCheck is used by the FilterInputs function in Example Code 9.1.
Setting Digital Outputs
The ClickDioSet function is used to set the state of the digital (contact closure) output. The
two different digital outputs are labeled D1 and D2. The state of the outputs can be set to
either open (0) or closed (1). The ClickDioSet function is used by the ChangeSignalLight
function in Example Code 9.1.
Example Code 9.1
This example simulates a traffic signal light progressing through the green, yellow and red
indications:
˽
RED – If the light is red, the RED1 LED will be on and the digital 1 output will be
closed.
˽
YELLOW – If the light is yellow, the YELLOW1 LED will be on and the digital 2 output
will be closed.
˽
GREEN – If the light is green, neither the RED1 nor the YELLOW1 LEDs will be on
and both contact closure outputs will be open. If the push-button is pressed while the
light is green, then the green time will be extended.
By wiring the digital outputs to the digital inputs, the MonitorSignalLight interrupt service
routine will be used to echo the status of the signal light on RED4 and YELLOW4. The ISR
requires a set up time specified by the directive REQUIRED_ISR_TICK_COUNT before
the inputs are considered to be stable. This helps prevent glitches from flickering the status
of the LEDs used to simulate a traffic light. In addition a state machine also helps filter out
conditions where both red and yellow are off momentarily. In the real world, this may occur
for just a few milliseconds when the light is switched from yellow to red.