Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added interface panel example to show how to change IO pin at runtime
- Loading branch information
philr
committed
Jan 22, 2018
1 parent
30b4197
commit afc2d4b
Showing
2 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
examples/InterfacePanel/ConfigurableOutputPin/ConfigurableOutputPin.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* ************************************************************************ | ||
Configurable Output Pin | ||
This program demonstrates how MegunoLink's Interface Panel and our command | ||
handler Arduino library can be used to reconfigure which IO pin your device | ||
is using at runtime. | ||
The example folder also contains a MegunoLink project, with an Interface | ||
Panel to control the IO Pin. | ||
Visit: | ||
* http://www.MegunoLink.com to download MegunoLink. | ||
************************************************************************ */ | ||
|
||
#include "MegunoLink.h" | ||
#include "CommandHandler.h" | ||
|
||
|
||
int IOPort = 9; //initial IO pin number | ||
|
||
long LastToggleTime = 0; // Time we last toggled the IO | ||
int OnTime = 10; // Amount of time the IO remains on [milliseconds] | ||
int OffTime = 100; // Amount of time the IO remains off [milliseconds] | ||
|
||
CommandHandler<> SerialCommandHandler; | ||
|
||
void Cmd_SetIOPin(CommandParameter &Parameters) | ||
{ | ||
Serial.print("Setting IO Port to:"); | ||
IOPort = Parameters.NextParameterAsInteger(); | ||
pinMode(IOPort, OUTPUT); | ||
Serial.println(IOPort); | ||
} | ||
|
||
void setup() | ||
{ | ||
Serial.begin(9600); | ||
Serial.println("Configurable IO Pin Demo"); | ||
Serial.println("-----------------------------"); | ||
|
||
pinMode(IOPort, OUTPUT); | ||
|
||
SerialCommandHandler.AddCommand(F("SetIOPin"), Cmd_SetIOPin); | ||
} | ||
|
||
void loop() | ||
{ | ||
SerialCommandHandler.Process(); | ||
|
||
// Toggle the IO Pin | ||
uint32_t uNow = millis(); | ||
if (uNow - LastToggleTime < OnTime) | ||
digitalWrite(IOPort, HIGH); | ||
else | ||
digitalWrite(IOPort, LOW); | ||
|
||
if (uNow - LastToggleTime > OnTime + OffTime) | ||
LastToggleTime = uNow; | ||
} |
189 changes: 189 additions & 0 deletions
189
examples/InterfacePanel/ConfigurableOutputPin/ConfigurableOutputPin.mlx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<meguno-link-project version="1.0"> | ||
<culture>en-NZ</culture> | ||
<data> | ||
<shared-visualizer-data> | ||
<data id="SerialMonitorData" name="" instance-id="db7b66d6-0760-4a56-a7d9-6b20509e2c86"> | ||
<send-cr-default>true</send-cr-default> | ||
<send-lf-default>true</send-lf-default> | ||
<word-wrap-default>true</word-wrap-default> | ||
<include-date>false</include-date> | ||
<include-time>false</include-time> | ||
<include-custom>false</include-custom> | ||
<custom-time-stamp /> | ||
<clear-on-send>false</clear-on-send> | ||
<message-history> | ||
<item>!SetIOPin 10\r</item> | ||
<item>!SetIOPin 9\r</item> | ||
</message-history> | ||
</data> | ||
<data id="UploadManagerData" name="" instance-id="93613efb-c7ff-4c14-9a7d-4d8aa71aa4d5"> | ||
<verify>true</verify> | ||
<uploads /> | ||
</data> | ||
</shared-visualizer-data> | ||
</data> | ||
<reporting> | ||
<generate-scheduled-reports>false</generate-scheduled-reports> | ||
<destinations> | ||
<report-to-folder> | ||
<last-report-number>0</last-report-number> | ||
<folder-path /> | ||
<use-sub-folder>true</use-sub-folder> | ||
<sub-folder-pattern>Report {Seq}</sub-folder-pattern> | ||
<enabled>true</enabled> | ||
<period>PT1H</period> | ||
<last-sent>0001-01-01T00:00:00</last-sent> | ||
</report-to-folder> | ||
</destinations> | ||
</reporting> | ||
<serial-sources> | ||
<default>1</default> | ||
<sources> | ||
<source type="SharedRS232Port"> | ||
<id>1</id> | ||
<display-name>Serial Connection</display-name> | ||
<sort-order>0</sort-order> | ||
<port-name> | ||
<type>Fixed</type> | ||
<port>COM17</port> | ||
</port-name> | ||
<baud-rate>9600</baud-rate> | ||
<data-bits>8</data-bits> | ||
<handshaking>None</handshaking> | ||
<parity>None</parity> | ||
<stop-bits>One</stop-bits> | ||
<disable-dtr>false</disable-dtr> | ||
<disable-rts>false</disable-rts> | ||
</source> | ||
</sources> | ||
<connect-sources /> | ||
</serial-sources> | ||
<windows> | ||
<window> | ||
<DockPanel FormatVersion="1.0" DockLeftPortion="0.15" DockRightPortion="0.0970031545741325" DockTopPortion="0.25" DockBottomPortion="0.25" ActiveDocumentPane="3" ActivePane="3"> | ||
<Contents Count="4"> | ||
<Content ID="0" PersistString="VisualizerToolbox" AutoHidePortion="0.25" IsHidden="False" IsFloat="False" /> | ||
<Content ID="1" PersistString="SourceManager" AutoHidePortion="0.25" IsHidden="False" IsFloat="False"> | ||
<instance-id>e0727d12-02ab-441c-acc7-39e25e8b1618</instance-id> | ||
<ShowSourceInTitle>false</ShowSourceInTitle> | ||
<ShowPortInTitle>true</ShowPortInTitle> | ||
<SourceId>1</SourceId> | ||
<TabTitle>Connection Manager</TabTitle> | ||
</Content> | ||
<Content ID="2" PersistString="SerialMonitor" AutoHidePortion="0.25" IsHidden="False" IsFloat="False"> | ||
<InsertTimestamp>false</InsertTimestamp> | ||
<WordWrap>true</WordWrap> | ||
<IncludeDate>false</IncludeDate> | ||
<IncludeTime>false</IncludeTime> | ||
<IncludeCustom>false</IncludeCustom> | ||
<CustomTimeStamp /> | ||
<AutoScroll>false</AutoScroll> | ||
<ShowEOLMarkers>false</ShowEOLMarkers> | ||
<ShowLineTime>false</ShowLineTime> | ||
<ShowLineDate>false</ShowLineDate> | ||
<instance-id>c274883c-5425-442a-950c-08fad6ce311b</instance-id> | ||
<ShowSourceInTitle>true</ShowSourceInTitle> | ||
<ShowPortInTitle>false</ShowPortInTitle> | ||
<SourceId>1</SourceId> | ||
<TabTitle>Monitor</TabTitle> | ||
</Content> | ||
<Content ID="3" PersistString="InterfacePanel" AutoHidePortion="0.25" IsHidden="False" IsFloat="False"> | ||
<design type="InterfacePanel"> | ||
<children child-list="Controls"> | ||
<component type="IPControlLibrary.Controls.IPButton, IPControlLibrary, Version=1.19.18003.103, Culture=neutral, PublicKeyToken=null" name="SetIOButton"> | ||
<properties> | ||
<property name="OnClickSend">!SetIOPin [IOPinNumericUpDown.Value]\r</property> | ||
<property name="Text">Set IO Pin</property> | ||
<property name="Location">146, 25</property> | ||
<property name="Name">SetIOButton</property> | ||
<property name="Size">75, 23</property> | ||
<property name="TabIndex">2</property> | ||
</properties> | ||
</component> | ||
<component type="IPControlLibrary.Controls.IPNumericUpDown, IPControlLibrary, Version=1.19.18003.103, Culture=neutral, PublicKeyToken=null" name="IOPinNumericUpDown"> | ||
<children child-list="Controls" /> | ||
<properties> | ||
<property name="OnValueChangedSend" /> | ||
<property name="Value">9</property> | ||
<property name="Location">19, 26</property> | ||
<property name="Name">IOPinNumericUpDown</property> | ||
<property name="Size">120, 20</property> | ||
<property name="TabIndex">1</property> | ||
</properties> | ||
</component> | ||
</children> | ||
<properties> | ||
<property name="Name">UserControl1</property> | ||
<property name="Size">556, 358</property> | ||
</properties> | ||
<components /> | ||
</design> | ||
<values> | ||
<value name="SetIOButton"> | ||
<property name="Enabled"><![CDATA[True]]></property> | ||
</value> | ||
<value name="IOPinNumericUpDown"> | ||
<property name="Value"><![CDATA[9]]></property> | ||
<property name="Minimum"><![CDATA[0]]></property> | ||
<property name="Maximum"><![CDATA[100]]></property> | ||
<property name="Enabled"><![CDATA[True]]></property> | ||
</value> | ||
</values> | ||
<instance-id>9c255fc7-299b-4edf-92d5-8d38d44e1d74</instance-id> | ||
<ShowSourceInTitle>false</ShowSourceInTitle> | ||
<ShowPortInTitle>false</ShowPortInTitle> | ||
<SourceId>1</SourceId> | ||
<TabTitle>Interface Panel</TabTitle> | ||
</Content> | ||
</Contents> | ||
<Panes Count="4"> | ||
<Pane ID="0" DockState="DockRightAutoHide" ActiveContent="0"> | ||
<Contents Count="1"> | ||
<Content ID="0" RefID="0" /> | ||
</Contents> | ||
</Pane> | ||
<Pane ID="1" DockState="Document" ActiveContent="2"> | ||
<Contents Count="1"> | ||
<Content ID="0" RefID="2" /> | ||
</Contents> | ||
</Pane> | ||
<Pane ID="2" DockState="Document" ActiveContent="1"> | ||
<Contents Count="1"> | ||
<Content ID="0" RefID="1" /> | ||
</Contents> | ||
</Pane> | ||
<Pane ID="3" DockState="Document" ActiveContent="3"> | ||
<Contents Count="1"> | ||
<Content ID="0" RefID="3" /> | ||
</Contents> | ||
</Pane> | ||
</Panes> | ||
<DockWindows> | ||
<DockWindow ID="0" DockState="Document" ZOrderIndex="0"> | ||
<NestedPanes Count="3"> | ||
<Pane ID="0" RefID="1" PrevPane="-1" Alignment="Right" Proportion="0.5" /> | ||
<Pane ID="1" RefID="2" PrevPane="1" Alignment="Top" Proportion="0.190582959641256" /> | ||
<Pane ID="2" RefID="3" PrevPane="1" Alignment="Bottom" Proportion="0.5" /> | ||
</NestedPanes> | ||
</DockWindow> | ||
<DockWindow ID="1" DockState="DockLeft" ZOrderIndex="1"> | ||
<NestedPanes Count="0" /> | ||
</DockWindow> | ||
<DockWindow ID="2" DockState="DockRight" ZOrderIndex="2"> | ||
<NestedPanes Count="1"> | ||
<Pane ID="0" RefID="0" PrevPane="-1" Alignment="Bottom" Proportion="0.5" /> | ||
</NestedPanes> | ||
</DockWindow> | ||
<DockWindow ID="3" DockState="DockTop" ZOrderIndex="3"> | ||
<NestedPanes Count="0" /> | ||
</DockWindow> | ||
<DockWindow ID="4" DockState="DockBottom" ZOrderIndex="4"> | ||
<NestedPanes Count="0" /> | ||
</DockWindow> | ||
</DockWindows> | ||
<FloatWindows Count="0" /> | ||
</DockPanel> | ||
</window> | ||
</windows> | ||
</meguno-link-project> |