working relay, but i returned to using the monstermotor shield. and now with beter stop code for the motors

This commit is contained in:
5shekel 2016-04-13 19:06:03 +02:00
parent d3eb3d9962
commit fe81d3b4c0
4 changed files with 140 additions and 129 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 58 KiB

View File

@ -483,7 +483,7 @@ design rules under a new name.
<attribute name="MF" value="" x="44.45" y="7.62" size="1.778" layer="27" display="off"/> <attribute name="MF" value="" x="44.45" y="7.62" size="1.778" layer="27" display="off"/>
<attribute name="OC_FARNELL" value="unknown" x="44.45" y="7.62" size="1.778" layer="27" display="off"/> <attribute name="OC_FARNELL" value="unknown" x="44.45" y="7.62" size="1.778" layer="27" display="off"/>
</element> </element>
<element name="Q1" library="dp_devices" package="TO-92" value="" x="25.4" y="5.08" rot="R270"/> <element name="Q1" library="dp_devices" package="TO-92" value="" x="25.4" y="3.81" rot="R270"/>
<element name="R1" library="adafruit" package="0204/7" value="" x="15.24" y="2.54"/> <element name="R1" library="adafruit" package="0204/7" value="" x="15.24" y="2.54"/>
<element name="J1" library="adafruit" package="1X2-3.5MM" value="1X2-3.5MM" x="3.81" y="20.32" smashed="yes" rot="R270"/> <element name="J1" library="adafruit" package="1X2-3.5MM" value="1X2-3.5MM" x="3.81" y="20.32" smashed="yes" rot="R270"/>
<element name="R2" library="adafruit" package="0204/7" value="" x="15.24" y="7.62"/> <element name="R2" library="adafruit" package="0204/7" value="" x="15.24" y="7.62"/>
@ -498,51 +498,54 @@ design rules under a new name.
<attribute name="MF" value="" x="39.37" y="21.59" size="1.778" layer="27" display="off"/> <attribute name="MF" value="" x="39.37" y="21.59" size="1.778" layer="27" display="off"/>
<attribute name="OC_FARNELL" value="unknown" x="39.37" y="21.59" size="1.778" layer="27" display="off"/> <attribute name="OC_FARNELL" value="unknown" x="39.37" y="21.59" size="1.778" layer="27" display="off"/>
</element> </element>
<element name="Q2" library="dp_devices" package="TO-92" value="" x="25.4" y="12.7" rot="R90"/> <element name="Q2" library="dp_devices" package="TO-92" value="" x="25.4" y="11.43" rot="R90"/>
</elements> </elements>
<signals> <signals>
<signal name="N$1"> <signal name="N$1">
<contactref element="Q1" pad="2"/> <contactref element="Q1" pad="2"/>
<contactref element="R1" pad="2"/> <contactref element="R1" pad="2"/>
<wire x1="19.05" y1="2.54" x2="20.32" y2="2.54" width="0.6096" layer="1"/> <wire x1="19.05" y1="2.54" x2="20.32" y2="2.54" width="0.6096" layer="1"/>
<wire x1="20.32" y1="2.54" x2="22.86" y2="5.08" width="0.6096" layer="1"/> <wire x1="20.32" y1="2.54" x2="22.86" y2="3.81" width="0.6096" layer="1"/>
<wire x1="22.86" y1="5.08" x2="25.4" y2="5.08" width="0.6096" layer="1"/> <wire x1="22.86" y1="3.81" x2="25.4" y2="3.81" width="0.6096" layer="1"/>
</signal> </signal>
<signal name="+12V"> <signal name="+12V">
<contactref element="J1" pad="2"/> <contactref element="J1" pad="2"/>
<contactref element="K2" pad="1"/> <contactref element="K2" pad="1"/>
<contactref element="K1" pad="P1"/>
<contactref element="K1" pad="1"/> <contactref element="K1" pad="1"/>
<wire x1="3.81" y1="22.02" x2="3.81" y2="25.4" width="0.6096" layer="1"/> <wire x1="3.81" y1="22.02" x2="3.81" y2="25.4" width="0.6096" layer="1"/>
<wire x1="3.81" y1="25.4" x2="35.56" y2="25.4" width="0.6096" layer="1"/> <wire x1="3.81" y1="25.4" x2="35.56" y2="25.4" width="0.6096" layer="1"/>
<wire x1="35.56" y1="25.4" x2="40.64" y2="25.4" width="0.6096" layer="1"/> <wire x1="35.56" y1="25.4" x2="40.64" y2="25.4" width="0.6096" layer="1"/>
<wire x1="40.64" y1="25.4" x2="40.64" y2="11.43" width="0.6096" layer="1"/> <wire x1="40.64" y1="25.4" x2="40.64" y2="21.59" width="0.6096" layer="1"/>
<wire x1="40.64" y1="11.43" x2="52.07" y2="11.43" width="0.6096" layer="1"/> <contactref element="K2" pad="P1"/>
<wire x1="60.96" y1="3.81" x2="60.96" y2="0" width="0.6096" layer="1"/> <wire x1="40.64" y1="11.43" x2="40.64" y2="21.59" width="0.6096" layer="1"/>
<wire x1="60.96" y1="0" x2="52.07" y2="0" width="0.6096" layer="1"/> <wire x1="40.64" y1="21.59" x2="55.88" y2="21.59" width="0.6096" layer="1"/>
<wire x1="52.07" y1="0" x2="52.07" y2="11.43" width="0.6096" layer="1"/> <wire x1="55.88" y1="21.59" x2="55.88" y2="17.78" width="0.6096" layer="1"/>
</signal> </signal>
<signal name="GND"> <signal name="GND">
<contactref element="Q1" pad="1"/> <contactref element="Q1" pad="1"/>
<contactref element="J1" pad="1"/> <contactref element="J1" pad="1"/>
<contactref element="Q2" pad="1"/> <contactref element="Q2" pad="1"/>
<contactref element="JP1" pad="2"/> <contactref element="JP1" pad="2"/>
<wire x1="3.81" y1="18.52" x2="3.81" y2="13.97" width="0.6096" layer="1"/> <wire x1="3.81" y1="18.52" x2="3.81" y2="16.51" width="0.6096" layer="16"/>
<wire x1="3.81" y1="13.97" x2="2.54" y2="12.7" width="0.6096" layer="1"/> <wire x1="3.81" y1="16.51" x2="2.54" y2="15.24" width="0.6096" layer="16"/>
<wire x1="2.54" y1="12.7" x2="2.54" y2="5.08" width="0.6096" layer="1"/> <wire x1="2.54" y1="15.24" x2="2.54" y2="5.08" width="0.6096" layer="16"/>
<wire x1="2.54" y1="5.08" x2="5.08" y2="5.08" width="0.6096" layer="1"/> <wire x1="2.54" y1="5.08" x2="5.08" y2="5.08" width="0.6096" layer="16"/>
<wire x1="5.08" y1="5.08" x2="20.32" y2="5.08" width="0.6096" layer="1"/> <wire x1="5.08" y1="5.08" x2="22.86" y2="5.08" width="0.6096" layer="16"/>
<wire x1="20.32" y1="5.08" x2="22.86" y2="7.62" width="0.6096" layer="1"/> <wire x1="22.86" y1="5.08" x2="24.13" y2="6.35" width="0.6096" layer="16"/>
<wire x1="22.86" y1="7.62" x2="25.4" y2="7.62" width="0.6096" layer="1"/> <wire x1="24.13" y1="6.35" x2="25.4" y2="6.35" width="0.6096" layer="16"/>
<wire x1="25.4" y1="10.16" x2="25.4" y2="7.62" width="0.6096" layer="1"/> <wire x1="25.4" y1="6.35" x2="25.4" y2="8.89" width="0.6096" layer="16"/>
<contactref element="K2" pad="P1"/> <contactref element="K1" pad="P2"/>
<wire x1="25.4" y1="10.16" x2="55.88" y2="17.78" width="0" layer="19" extent="1-1"/> <wire x1="25.4" y1="8.89" x2="25.4" y2="7.62" width="0.6096" layer="16"/>
<wire x1="25.4" y1="7.62" x2="53.34" y2="7.62" width="0.6096" layer="16"/>
<wire x1="53.34" y1="7.62" x2="53.34" y2="13.97" width="0.6096" layer="16"/>
<wire x1="53.34" y1="13.97" x2="60.96" y2="13.97" width="0.6096" layer="16"/>
<wire x1="60.96" y1="13.97" x2="60.96" y2="11.43" width="0.6096" layer="16"/>
</signal> </signal>
<signal name="N$3"> <signal name="N$3">
<contactref element="R2" pad="2"/> <contactref element="R2" pad="2"/>
<contactref element="Q2" pad="2"/> <contactref element="Q2" pad="2"/>
<wire x1="19.05" y1="7.62" x2="24.13" y2="12.7" width="0.6096" layer="1"/> <wire x1="19.05" y1="7.62" x2="19.05" y2="11.43" width="0.6096" layer="1"/>
<wire x1="24.13" y1="12.7" x2="25.4" y2="12.7" width="0.6096" layer="1"/> <wire x1="19.05" y1="11.43" x2="25.4" y2="11.43" width="0.6096" layer="1"/>
</signal> </signal>
<signal name="N$6"> <signal name="N$6">
<contactref element="K1" pad="S1"/> <contactref element="K1" pad="S1"/>
@ -568,20 +571,25 @@ design rules under a new name.
<contactref element="R2" pad="1"/> <contactref element="R2" pad="1"/>
<wire x1="5.08" y1="7.62" x2="11.43" y2="7.62" width="0.6096" layer="1"/> <wire x1="5.08" y1="7.62" x2="11.43" y2="7.62" width="0.6096" layer="1"/>
</signal> </signal>
<signal name="N$10">
<contactref element="K1" pad="P2"/>
<contactref element="K2" pad="S1"/>
<wire x1="60.96" y1="17.78" x2="60.96" y2="11.43" width="0.6096" layer="1"/>
</signal>
<signal name="N$4"> <signal name="N$4">
<contactref element="Q2" pad="3"/> <contactref element="Q2" pad="3"/>
<contactref element="K2" pad="2"/> <contactref element="K2" pad="2"/>
<wire x1="25.4" y1="15.24" x2="35.56" y2="17.78" width="0.6096" layer="1"/> <wire x1="25.4" y1="13.97" x2="25.4" y2="17.78" width="0.6096" layer="1"/>
<wire x1="25.4" y1="17.78" x2="35.56" y2="17.78" width="0.6096" layer="1"/>
</signal> </signal>
<signal name="N$8"> <signal name="N$8">
<contactref element="Q1" pad="3"/> <contactref element="Q1" pad="3"/>
<contactref element="K1" pad="2"/> <contactref element="K1" pad="2"/>
<wire x1="25.4" y1="2.54" x2="40.64" y2="3.81" width="0.6096" layer="1"/> <wire x1="25.4" y1="1.27" x2="35.56" y2="1.27" width="0.6096" layer="1"/>
<wire x1="35.56" y1="1.27" x2="38.1" y2="3.81" width="0.6096" layer="1"/>
<wire x1="38.1" y1="3.81" x2="40.64" y2="3.81" width="0.6096" layer="1"/>
</signal>
<signal name="N$2">
<contactref element="K2" pad="S1"/>
<contactref element="K1" pad="P1"/>
<wire x1="60.96" y1="17.78" x2="58.42" y2="17.78" width="0.6096" layer="1"/>
<wire x1="58.42" y1="17.78" x2="58.42" y2="3.81" width="0.6096" layer="1"/>
<wire x1="58.42" y1="3.81" x2="60.96" y2="3.81" width="0.6096" layer="1"/>
</signal> </signal>
</signals> </signals>
</board> </board>

View File

@ -2690,13 +2690,14 @@ type 0309, grid 2.5 mm</description>
</plain> </plain>
<instances> <instances>
<instance part="K1" gate="1" x="41.91" y="74.93" smashed="yes"> <instance part="K1" gate="1" x="41.91" y="74.93" smashed="yes">
<attribute name="VALUE" x="43.18" y="70.231" size="1.778" layer="96"/> <attribute name="VALUE" x="43.18" y="77.851" size="1.778" layer="96"/>
<attribute name="PART" x="43.18" y="80.01" size="1.778" layer="95"/>
</instance> </instance>
<instance part="K1" gate="2" x="64.77" y="68.58" smashed="yes" rot="R270"> <instance part="K1" gate="2" x="74.93" y="59.69" smashed="yes" rot="R270">
<attribute name="PART" x="64.77" y="66.04" size="1.778" layer="95" rot="R270"/> <attribute name="PART" x="74.93" y="57.15" size="1.778" layer="95" rot="R270"/>
</instance> </instance>
<instance part="K1" gate="3" x="64.77" y="52.07" smashed="yes" rot="R270"> <instance part="K1" gate="3" x="74.93" y="43.18" smashed="yes" rot="R270">
<attribute name="PART" x="64.77" y="49.53" size="1.778" layer="95" rot="R270"/> <attribute name="PART" x="74.93" y="40.64" size="1.778" layer="95" rot="R270"/>
</instance> </instance>
<instance part="Q1" gate="Q" x="39.37" y="63.5" smashed="yes"> <instance part="Q1" gate="Q" x="39.37" y="63.5" smashed="yes">
<attribute name="NAME" x="35.56" y="64.77" size="1.778" layer="95"/> <attribute name="NAME" x="35.56" y="64.77" size="1.778" layer="95"/>
@ -2705,23 +2706,23 @@ type 0309, grid 2.5 mm</description>
<instance part="R1" gate="G$1" x="13.97" y="63.5"/> <instance part="R1" gate="G$1" x="13.97" y="63.5"/>
<instance part="J1" gate="G$1" x="-10.16" y="86.36" rot="R180"/> <instance part="J1" gate="G$1" x="-10.16" y="86.36" rot="R180"/>
<instance part="R2" gate="G$1" x="13.97" y="36.83"/> <instance part="R2" gate="G$1" x="13.97" y="36.83"/>
<instance part="J2" gate="G$1" x="90.17" y="59.69"/> <instance part="J2" gate="G$1" x="100.33" y="50.8"/>
<instance part="JP1" gate="A" x="6.35" y="52.07" rot="R180"/> <instance part="JP1" gate="A" x="6.35" y="52.07" rot="R180"/>
<instance part="U$3" gate="G$1" x="41.91" y="54.61"/> <instance part="U$3" gate="G$1" x="41.91" y="54.61"/>
<instance part="U$1" gate="G$1" x="-2.54" y="80.01"/> <instance part="U$1" gate="G$1" x="-2.54" y="80.01"/>
<instance part="+12V2" gate="SUPPLY" x="-2.54" y="86.36"/> <instance part="+12V2" gate="SUPPLY" x="-2.54" y="86.36"/>
<instance part="K2" gate="1" x="29.21" y="48.26" smashed="yes"> <instance part="K2" gate="1" x="29.21" y="48.26" smashed="yes">
<attribute name="VALUE" x="30.48" y="43.561" size="1.778" layer="96"/> <attribute name="VALUE" x="30.48" y="51.181" size="1.778" layer="96"/>
<attribute name="PART" x="22.86" y="50.8" size="1.778" layer="95"/> <attribute name="PART" x="30.48" y="53.34" size="1.778" layer="95"/>
</instance> </instance>
<instance part="K2" gate="2" x="54.61" y="46.99" rot="R270"/> <instance part="K2" gate="2" x="63.5" y="54.61" rot="R270"/>
<instance part="Q2" gate="Q" x="26.67" y="36.83" smashed="yes"> <instance part="Q2" gate="Q" x="26.67" y="36.83" smashed="yes">
<attribute name="NAME" x="22.86" y="38.1" size="1.778" layer="95"/> <attribute name="NAME" x="22.86" y="38.1" size="1.778" layer="95"/>
<attribute name="VALUE" x="16.51" y="41.91" size="1.778" layer="96"/> <attribute name="VALUE" x="16.51" y="41.91" size="1.778" layer="96"/>
</instance> </instance>
<instance part="U$4" gate="G$1" x="29.21" y="27.94"/> <instance part="U$4" gate="G$1" x="29.21" y="27.94"/>
<instance part="U$5" gate="G$1" x="-2.54" y="48.26"/> <instance part="U$5" gate="G$1" x="-2.54" y="48.26"/>
<instance part="U$2" gate="G$1" x="52.07" y="39.37"/> <instance part="U$2" gate="G$1" x="59.69" y="40.64"/>
</instances> </instances>
<busses> <busses>
</busses> </busses>
@ -2740,12 +2741,6 @@ type 0309, grid 2.5 mm</description>
<wire x1="-2.54" y1="86.36" x2="-5.08" y2="86.36" width="0.1524" layer="91"/> <wire x1="-2.54" y1="86.36" x2="-5.08" y2="86.36" width="0.1524" layer="91"/>
</segment> </segment>
<segment> <segment>
<pinref part="K1" gate="2" pin="P"/>
<wire x1="59.69" y1="68.58" x2="62.23" y2="68.58" width="0.1524" layer="91"/>
<wire x1="59.69" y1="68.58" x2="59.69" y2="74.93" width="0.1524" layer="91"/>
<label x="59.69" y="76.2" size="1.778" layer="95" rot="R90" xref="yes"/>
</segment>
<segment>
<pinref part="K2" gate="1" pin="1"/> <pinref part="K2" gate="1" pin="1"/>
<wire x1="29.21" y1="53.34" x2="29.21" y2="59.69" width="0.1524" layer="91"/> <wire x1="29.21" y1="53.34" x2="29.21" y2="59.69" width="0.1524" layer="91"/>
<label x="27.94" y="58.42" size="1.778" layer="95" rot="R180" xref="yes"/> <label x="27.94" y="58.42" size="1.778" layer="95" rot="R180" xref="yes"/>
@ -2755,6 +2750,11 @@ type 0309, grid 2.5 mm</description>
<wire x1="41.91" y1="82.55" x2="41.91" y2="80.01" width="0.1524" layer="91"/> <wire x1="41.91" y1="82.55" x2="41.91" y2="80.01" width="0.1524" layer="91"/>
<label x="41.91" y="83.82" size="1.778" layer="95" rot="R90" xref="yes"/> <label x="41.91" y="83.82" size="1.778" layer="95" rot="R90" xref="yes"/>
</segment> </segment>
<segment>
<pinref part="K2" gate="2" pin="P"/>
<wire x1="60.96" y1="54.61" x2="58.42" y2="54.61" width="0.1524" layer="91"/>
<label x="58.42" y="54.61" size="1.778" layer="95" rot="R180" xref="yes"/>
</segment>
</net> </net>
<net name="GND" class="0"> <net name="GND" class="0">
<segment> <segment>
@ -2780,9 +2780,9 @@ type 0309, grid 2.5 mm</description>
<pinref part="JP1" gate="A" pin="2"/> <pinref part="JP1" gate="A" pin="2"/>
</segment> </segment>
<segment> <segment>
<pinref part="K2" gate="2" pin="P"/> <pinref part="K1" gate="3" pin="P"/>
<pinref part="U$2" gate="G$1" pin="GND"/> <pinref part="U$2" gate="G$1" pin="GND"/>
<wire x1="52.07" y1="46.99" x2="52.07" y2="41.91" width="0.1524" layer="91"/> <wire x1="59.69" y1="43.18" x2="72.39" y2="43.18" width="0.1524" layer="91"/>
</segment> </segment>
</net> </net>
<net name="N$3" class="0"> <net name="N$3" class="0">
@ -2795,26 +2795,26 @@ type 0309, grid 2.5 mm</description>
<net name="N$6" class="0"> <net name="N$6" class="0">
<segment> <segment>
<pinref part="K1" gate="2" pin="S"/> <pinref part="K1" gate="2" pin="S"/>
<wire x1="69.85" y1="73.66" x2="76.2" y2="73.66" width="0.1524" layer="91"/> <wire x1="80.01" y1="64.77" x2="86.36" y2="64.77" width="0.1524" layer="91"/>
<wire x1="76.2" y1="73.66" x2="82.55" y2="73.66" width="0.1524" layer="91"/> <wire x1="86.36" y1="64.77" x2="92.71" y2="64.77" width="0.1524" layer="91"/>
<wire x1="82.55" y1="73.66" x2="85.09" y2="71.12" width="0.1524" layer="91"/> <wire x1="92.71" y1="64.77" x2="95.25" y2="62.23" width="0.1524" layer="91"/>
<pinref part="J2" gate="G$1" pin="1"/> <pinref part="J2" gate="G$1" pin="1"/>
<wire x1="85.09" y1="71.12" x2="85.09" y2="62.23" width="0.1524" layer="91"/> <wire x1="95.25" y1="62.23" x2="95.25" y2="53.34" width="0.1524" layer="91"/>
<pinref part="K1" gate="3" pin="O"/> <pinref part="K1" gate="3" pin="O"/>
<wire x1="69.85" y1="46.99" x2="76.2" y2="46.99" width="0.1524" layer="91"/> <wire x1="80.01" y1="38.1" x2="86.36" y2="38.1" width="0.1524" layer="91"/>
<wire x1="76.2" y1="46.99" x2="76.2" y2="73.66" width="0.1524" layer="91"/> <wire x1="86.36" y1="38.1" x2="86.36" y2="64.77" width="0.1524" layer="91"/>
<junction x="76.2" y="73.66"/> <junction x="86.36" y="64.77"/>
</segment> </segment>
</net> </net>
<net name="N$7" class="0"> <net name="N$7" class="0">
<segment> <segment>
<pinref part="J2" gate="G$1" pin="2"/> <pinref part="J2" gate="G$1" pin="2"/>
<pinref part="K1" gate="3" pin="S"/> <pinref part="K1" gate="3" pin="S"/>
<wire x1="85.09" y1="59.69" x2="72.39" y2="59.69" width="0.1524" layer="91"/> <wire x1="95.25" y1="50.8" x2="82.55" y2="50.8" width="0.1524" layer="91"/>
<wire x1="72.39" y1="59.69" x2="69.85" y2="57.15" width="0.1524" layer="91"/> <wire x1="82.55" y1="50.8" x2="80.01" y2="48.26" width="0.1524" layer="91"/>
<pinref part="K1" gate="2" pin="O"/> <pinref part="K1" gate="2" pin="O"/>
<wire x1="69.85" y1="63.5" x2="69.85" y2="57.15" width="0.1524" layer="91"/> <wire x1="80.01" y1="54.61" x2="80.01" y2="48.26" width="0.1524" layer="91"/>
<junction x="69.85" y="57.15"/> <junction x="80.01" y="48.26"/>
</segment> </segment>
</net> </net>
<net name="N$9" class="0"> <net name="N$9" class="0">
@ -2831,13 +2831,6 @@ type 0309, grid 2.5 mm</description>
<wire x1="8.89" y1="49.53" x2="8.89" y2="36.83" width="0.1524" layer="91"/> <wire x1="8.89" y1="49.53" x2="8.89" y2="36.83" width="0.1524" layer="91"/>
</segment> </segment>
</net> </net>
<net name="N$10" class="0">
<segment>
<pinref part="K1" gate="3" pin="P"/>
<wire x1="62.23" y1="52.07" x2="59.69" y2="52.07" width="0.1524" layer="91"/>
<pinref part="K2" gate="2" pin="S"/>
</segment>
</net>
<net name="N$4" class="0"> <net name="N$4" class="0">
<segment> <segment>
<pinref part="Q2" gate="Q" pin="C"/> <pinref part="Q2" gate="Q" pin="C"/>
@ -2852,6 +2845,13 @@ type 0309, grid 2.5 mm</description>
<wire x1="41.91" y1="69.85" x2="41.91" y2="68.58" width="0.1524" layer="91"/> <wire x1="41.91" y1="69.85" x2="41.91" y2="68.58" width="0.1524" layer="91"/>
</segment> </segment>
</net> </net>
<net name="N$2" class="0">
<segment>
<pinref part="K2" gate="2" pin="S"/>
<pinref part="K1" gate="2" pin="P"/>
<wire x1="68.58" y1="59.69" x2="72.39" y2="59.69" width="0.1524" layer="91"/>
</segment>
</net>
</nets> </nets>
</sheet> </sheet>
</sheets> </sheets>

View File

@ -6,24 +6,24 @@
#define DEBUG 1 #define DEBUG 1
byte addresses[][7] = {"ampBot","ampCtl"}; byte addresses[][7] = {"ampBot", "ampCtl"};
typedef enum { role_ping_out = 1, role_pong_back } role_e; // The various roles supported by this sketch typedef enum { role_ping_out = 1, role_pong_back } role_e; // The various roles supported by this sketch
role_e role ; role_e role ;
/** /**
* Create a data structure for transmitting and receiving data Create a data structure for transmitting and receiving data
* This allows many variables to be easily sent and received in a single transmission This allows many variables to be easily sent and received in a single transmission
* See http://www.cplusplus.com/doc/tutorial/structures/ See http://www.cplusplus.com/doc/tutorial/structures/
*/ */
struct dataStruct{ struct dataStruct {
unsigned long _micros; unsigned long _micros;
int xin; int xin;
int yin; int yin;
}myData; } myData;
RF24 radio(9,8); //also miso/mosi at 11/12/13 RF24 radio(9, 8); //also miso/mosi at 11/12/13
#define role_pin 2 #define role_pin 2
/////// remote ///////////// /////// remote /////////////
#define AX_pin A0 #define AX_pin A0
@ -53,7 +53,7 @@ void setup() {
radio.openReadingPipe(1, addresses[0]); radio.openReadingPipe(1, addresses[0]);
radio.startListening(); radio.startListening();
if(DEBUG) Serial << "im a bot!" << endl; if (DEBUG) Serial << "im a bot!" << endl;
} else { } else {
role = role_ping_out; role = role_ping_out;
@ -61,10 +61,10 @@ void setup() {
radio.openReadingPipe(1, addresses[1]); radio.openReadingPipe(1, addresses[1]);
radio.stopListening(); radio.stopListening();
if(DEBUG) Serial << "im a controller!" << endl; if (DEBUG) Serial << "im a controller!" << endl;
} }
if(role==role_pong_back) if (role == role_pong_back)
{ {
// Initialize motor pins as outputs // Initialize motor pins as outputs
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
@ -79,7 +79,7 @@ void setup() {
digitalWrite(inApin[i], LOW); digitalWrite(inApin[i], LOW);
digitalWrite(inBpin[i], LOW); digitalWrite(inBpin[i], LOW);
} }
}else if(role == role_ping_out){ } else if (role == role_ping_out) {
pinMode(AX_pin, INPUT); pinMode(AX_pin, INPUT);
pinMode(AY_pin, INPUT); pinMode(AY_pin, INPUT);
} }
@ -87,16 +87,18 @@ void setup() {
void loop() { void loop() {
/****************** Ping Out Role ***************************/ /****************** Ping Out Role ***************************/
if (role == role_ping_out) { if (role == role_ping_out) {
myData.xin = analogRead(AX_pin); myData.xin = analogRead(AX_pin);
if(myData.xin == 517){ myData.xin = 518;} //terrible hack. if (myData.xin == 517) {
myData.xin = 518; //terrible hack.
}
myData.yin = analogRead(AY_pin); myData.yin = analogRead(AY_pin);
bool ok = radio.write( &myData, sizeof(myData) ); bool ok = radio.write( &myData, sizeof(myData) );
if(DEBUG) Serial<<"xin:"<<myData.xin<<" yin:"<<myData.yin<<endl; if (DEBUG) Serial << "xin:" << myData.xin << " yin:" << myData.yin << endl;
/* /*
if (ok) if (ok)
Serial << "transfer OK \n\r"; Serial << "transfer OK \n\r";
@ -107,12 +109,12 @@ void loop() {
/****************** Pong Back Role ***************************/ /****************** Pong Back Role ***************************/
else if ( role == role_pong_back ) else if ( role == role_pong_back )
{ {
if( radio.available()){ if ( radio.available()) {
// Variable for the received timestamp // Variable for the received timestamp
while (radio.available()) { // While there is data ready while (radio.available()) { // While there is data ready
radio.read( &myData, sizeof(myData) ); // Get the payload radio.read( &myData, sizeof(myData) ); // Get the payload
@ -124,18 +126,19 @@ void loop() {
leftMotorSpeed = constrain(y2pwm + x2pwm, -255, 255); leftMotorSpeed = constrain(y2pwm + x2pwm, -255, 255);
rightMotorSpeed = constrain(y2pwm - x2pwm, -255, 255); rightMotorSpeed = constrain(y2pwm - x2pwm, -255, 255);
if (myData.xin == 518 ) move(1, rightMotorSpeed);
stop(0);
else
move(0, leftMotorSpeed); move(0, leftMotorSpeed);
if (myData.yin == 521) if (myData.xin == 518 && myData.yin == 521) {
stop(0);
stop(1); stop(1);
else if (DEBUG) Serial << "im down:" << endl;
move(1, rightMotorSpeed);
if(DEBUG) Serial<<"left:"<<leftMotorSpeed<<" right:"<<rightMotorSpeed<<endl; delay(4); } else {
if(DEBUG) Serial<<"x:"<<myData.xin<<" y:"<<myData.yin<<endl; delay(4); if (DEBUG) Serial << "left:" << leftMotorSpeed << " right:" << rightMotorSpeed << endl;
if (DEBUG) Serial << "inY :" << myData.yin << " inX:" << myData.xin << endl;
}
delay(4);
} }
} }
@ -151,7 +154,7 @@ void move(int motor, int speed) {
digitalWrite(inApin[motor], HIGH); digitalWrite(inApin[motor], HIGH);
digitalWrite(inBpin[motor], LOW); digitalWrite(inBpin[motor], LOW);
} }
else{ else {
digitalWrite(inApin[motor], LOW); digitalWrite(inApin[motor], LOW);
digitalWrite(inBpin[motor], HIGH); digitalWrite(inBpin[motor], HIGH);
} }