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

Return to SDK Examples for Microchip Studio

1/*
2 * Title: WriteCCIODigitalOutput
3 *
4 * Objective:
5 * This example demonstrates how to initialize a CCIO-8 Expansion Board and
6 * write to its outputs.
7 *
8 * Description:
9 * This example sets up COM-0 to control a CCIO-8 Expansion Board then
10 * toggles the state of all of the CCIO-8's outputs from true to false.
11 *
12 * Requirements:
13 * ** A CCIO-8 Expansion Board powered and connected to COM-0.
14 * ** An output such as an LED connected to one or more of the CCIO-8's
15 * connectors.
16 * Note: You can leave the I/O points disconnected and still see the
17 * built-in I/O LEDs toggle with the connector state.
18 *
19 * Links:
20 * ** ClearCore Documentation: https://teknic-inc.github.io/ClearCore-library/
21 * ** ClearCore Manual: https://www.teknic.com/files/downloads/clearcore_user_manual.pdf
22 *
23 *
24 * Copyright (c) 2020 Teknic Inc. This work is free to use, copy and distribute under the terms of
25 * the standard MIT permissive software license which can be found at https://opensource.org/licenses/MIT
26 */
27
28#include "ClearCore.h"
29
30// Specify which ClearCore serial COM port is connected to the COM IN port
31// of the CCIO-8 board: ConnectorCOM0 or ConnectorCOM1.
32#define CcioPort ConnectorCOM0
33
34// The state to be written to each output connector.
35bool outputState;
36
37int main() {
38 // Set up the CCIO-8 COM port.
39 CcioPort.Mode(Connector::CCIO);
40 CcioPort.PortOpen();
41
42 // Using the CCIO-8 Board Manager, configure each connector on a single
43 // ClearCore I/O Expansion Board as an output. They can be either digital
44 // inputs or digital outputs.
45 // Note: If there is more than one CCIO-8 in the link, you may want to
46 // to change the limit of the for-loop from "CLEARCORE_PIN_CCIOA7" to the
47 // value of the last CCIO-8 connector to accommodate the additional boards.
48 // For example, if you are using three CCIO-8 boards, change this value to
49 // "CLEARCORE_PIN_CCIOC7", and do the same for the for-loop in the loop()
50 // function below.
51 for (int16_t pin = CLEARCORE_PIN_CCIOA0; pin <= CLEARCORE_PIN_CCIOA7; pin++) {
52 CcioMgr.PinByIndex(static_cast<ClearCorePins>(pin))->Mode(
53 Connector::OUTPUT_DIGITAL);
54 }
55
56 // The connectors are all set up; start the loop with turning them all on.
57 outputState = true;
58
59 while (true) {
60 // Send the current state to each of the outputs.
61 for (int16_t pin = CLEARCORE_PIN_CCIOA0; pin <= CLEARCORE_PIN_CCIOA7; pin++) {
62 CcioMgr.PinByIndex(static_cast<ClearCorePins>(pin))->State(outputState);
63 }
64
65 // Toggle the state to be written next time.
66 outputState = !outputState;
67
68 // Wait 1 second.
69 Delay_ms(1000);
70 }
71}
ClearCorePins
ClearCore PIN definitions.
Definition SysConnectors.h:54
@ CLEARCORE_PIN_CCIOA7
CCIO-8 board 1, connector 7.
Definition SysConnectors.h:96
@ CLEARCORE_PIN_CCIOA0
CCIO-8 board 1, connector 0.
Definition SysConnectors.h:89
void Delay_ms(uint32_t ms)
Blocks operations for ms milliseconds.
Definition SysTiming.h:287
CcioPin * PinByIndex(ClearCorePins connectorIndex)
Accessor for the individual CCIO-8 pin connectors.
int16_t State() override
In input mode, get the connector's last filtered sampled value. In output mode, get the connector's o...
virtual ConnectorModes Mode() override
Get the connector's operational mode.
Definition CcioPin.h:71