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

Return to SDK Examples for Microchip Studio

1/*
2 * Title: WriteCCIODigitalOutputPulses
3 *
4 * Objective:
5 * This example demonstrates how to initialize a CCIO-8 Expansion Board and
6 * write digital pulses to its outputs.
7 *
8 * Description:
9 * This example sets up COM-0 to control a CCIO-8 Expansion Board then
10 * writes a series of digital pulses to the defined connector.
11 *
12 * Requirements:
13 * ** A CCIO-8 Expansion Board powered and connected to COM-0.
14 * ** An output such as an LED connected to defined connector (CCIO-0).
15 * Note: You can leave the I/O point disconnected and still see the
16 * built-in I/O LED 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// Specify which ClearCore serial COM port is connected to the COM IN port
30// of the CCIO-8 board: ConnectorCOM0 or ConnectorCOM1.
31#define CcioPort ConnectorCOM0
32
33// Specify which output pin to write digital output pulses.
34// All connectors on the ClearCore I/O Expansion Board are capable of
35// pulsing the output.
36#define OutputPin CcioMgr.PinByIndex(CLEARCORE_PIN_CCIOA0)
37
38int main() {
39 // Set up the CCIO-8 COM port.
40 CcioPort.Mode(Connector::CCIO);
41 CcioPort.PortOpen();
42
43 // Set up the output connector in output mode.
44 OutputPin->Mode(Connector::OUTPUT_DIGITAL);
45
46 while (true) {
47 // Generate a 100ms on/100ms off pulse that runs until
48 // the stop function is called.
49 OutputPin->OutputPulsesStart(100, 100);
50 Delay_ms(1000);
51
52 // Stop any further pulses on the pin. The second argument controls how
53 // output pulses are stopped. If true, the output pulses will be stopped
54 // immediately (this is the default behavior); if false, the active
55 // pulse cycle will be completed first.
56 OutputPin->OutputPulsesStop(true);
57
58 // Generate a 250ms on/50ms off pulse that continues until
59 // 20 on/off cycles are complete or until the stop function
60 // is called.
61 OutputPin->OutputPulsesStart(250, 50, 20);
62 Delay_ms(6000);
63
64 // Pulses should be complete, but call stop to be safe.
65 OutputPin->OutputPulsesStop(true);
66
67 // Generate a 300ms on/500ms off pulse that runs for 5 complete cycles.
68 // With the final true argument, the sketch will pause here until all
69 // the pulse cycles are complete.
70 OutputPin->OutputPulsesStart(300, 500, 5, true);
71 Delay_ms(3000);
72 }
73}
void Delay_ms(uint32_t ms)
Blocks operations for ms milliseconds.
Definition SysTiming.h:287