ClearCore Library
Loading...
Searching...
No Matches
WriteDigitalOutput.cpp

Return to SDK Examples for Microchip Studio

1/*
2 * Title: WriteDigitalOutput
3 *
4 * Objective:
5 * This example demonstrates how to write the state of a ClearCore digital
6 * output.
7 *
8 * Description:
9 * This example repeatedly toggles the state of the ClearCore's six digital
10 * outputs, IO-0 through IO-5.
11 *
12 * Requirements:
13 * ** A device that takes in a digital signal connected to any of the I/O's,
14 * IO-0 through IO-5.
15 * Note: You can leave the I/O points disconnected and still see the
16 * built-in I/O LEDs toggle with the connector state.
17 *
18 * Links:
19 * ** ClearCore Documentation: https://teknic-inc.github.io/ClearCore-library/
20 * ** ClearCore Manual: https://www.teknic.com/files/downloads/clearcore_user_manual.pdf
21 *
22 *
23 * Copyright (c) 2020 Teknic Inc. This work is free to use, copy and distribute under the terms of
24 * the standard MIT permissive software license which can be found at https://opensource.org/licenses/MIT
25 */
26
27#include "ClearCore.h"
28
29// Declares a variable used to write new states to the output. We will toggle
30// this true/false.
31bool outputState;
32
33int main() {
34 // Configure pins IO-0 through IO-5 as digital outputs. These are the only
35 // pins that support digital output mode.
36 ConnectorIO0.Mode(Connector::OUTPUT_DIGITAL);
37 ConnectorIO1.Mode(Connector::OUTPUT_DIGITAL);
38 ConnectorIO2.Mode(Connector::OUTPUT_DIGITAL);
39 ConnectorIO3.Mode(Connector::OUTPUT_DIGITAL);
40 ConnectorIO4.Mode(Connector::OUTPUT_DIGITAL);
41 ConnectorIO5.Mode(Connector::OUTPUT_DIGITAL);
42
43 // The connectors are all set up; start the loop with turning them all on.
44 outputState = true;
45
46 while (true) {
47 // Toggle the digital output state.
48 if (outputState) {
49 ConnectorIO0.State(true);
50 ConnectorIO1.State(true);
51 ConnectorIO2.State(true);
52 ConnectorIO3.State(true);
53 ConnectorIO4.State(true);
54 ConnectorIO5.State(true);
55 }
56 else {
57 ConnectorIO0.State(false);
58 ConnectorIO1.State(false);
59 ConnectorIO2.State(false);
60 ConnectorIO3.State(false);
61 ConnectorIO4.State(false);
62 ConnectorIO5.State(false);
63 }
64
65 // Toggle the state to write in the next loop.
66 outputState = !outputState;
67
68 // Wait a second, then repeat.
69 Delay_ms(1000);
70 }
71}
void Delay_ms(uint32_t ms)
Blocks operations for ms milliseconds.
Definition SysTiming.h:287
int16_t State() override
Get connector's last sampled digital value.
virtual ConnectorModes Mode() override
Get the connector's operational mode.
Definition DigitalInOutAnalogOut.h:70
int16_t State() override
Get connector's last sampled value.
virtual ConnectorModes Mode() override
Get the connector's operational mode.
Definition DigitalInOutHBridge.h:124
virtual ConnectorModes Mode() override
Get the connector's operational mode.
Definition DigitalInOut.h:85
int16_t State() override
Get the connector's last majority-filtered sampled value.