Model Railroad System  2.2.2
Model RR signals with an Arduino
ProgrammingtheArduino.h
1 // -!- c++ -!- //////////////////////////////////////////////////////////////
2 //
3 // System :
4 // Module :
5 // Object Name : $RCSfile$
6 // Revision : $Revision$
7 // Date : $Date$
8 // Author : $Author$
9 // Created By : Robert Heller
10 // Created : Sun Jul 26 21:22:14 2015
11 // Last Modified : <150728.1024>
12 //
13 // Description
14 //
15 // Notes
16 //
17 // History
18 //
19 /////////////////////////////////////////////////////////////////////////////
20 //
21 // Copyright (C) 2015 Robert Heller D/B/A Deepwoods Software
22 // 51 Locke Hill Road
23 // Wendell, MA 01379-9728
24 //
25 // This program is free software; you can redistribute it and/or modify
26 // it under the terms of the GNU General Public License as published by
27 // the Free Software Foundation; either version 2 of the License, or
28 // (at your option) any later version.
29 //
30 // This program is distributed in the hope that it will be useful,
31 // but WITHOUT ANY WARRANTY; without even the implied warranty of
32 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 // GNU General Public License for more details.
34 //
35 // You should have received a copy of the GNU General Public License
36 // along with this program; if not, write to the Free Software
37 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
38 //
39 //
40 //
41 //////////////////////////////////////////////////////////////////////////////
42 
43 #ifndef __PROGRAMMINGTHEARDUINO_H
44 #define __PROGRAMMINGTHEARDUINO_H
45 /** @page ProgrammingtheArduino Programming the Arduino
46  * @htmlonly
47  * The C++ source code to download to the Arduino is in available for download
48  * as <a href="SignalDriverMax72xx.ino">SignalDriverMax72xx.ino</a>.
49  * @endhtmlonly
50  * @latexonly
51  * The C++ source code for the Arduino is in the file SignalDriverMax72xx.ino.
52  * @endlatexonly
53  * It uses the @e LedControl library, so the code starts by including the
54  * header file:
55  * @dontinclude SignalDriverMax72xx.ino
56  * @line LedControl
57  *
58  * Then since it is using scanf() and various string function, it includes
59  * stdio.h and string.h:
60  * @line stdio
61  * @until string
62  *
63  * Then it allocates a <strong>LedControl</strong> object:
64  * @skipline Create a new LedControl.
65  * @until lc1=LedControl
66  *
67  * Next the setup function initializes the MAX72xx chip and sends an
68  * announcement to the host computer over the serial port:
69  * @skipline setup
70  * @until }
71  *
72  * Next the signal aspects are defined. These values assuming that the signal
73  * heads are wired bottom to top, with the LEDs wired from bit 0 to 5 as:
74  * lower red, lower yellow, lower green, upper red, upper yellow, and upper
75  * green. (See @ref wiring Wiring the signals below.)
76  * @skipline Signal Aspects
77  * @until DARK
78  *
79  * Next we have a helper function to convert from an aspect name sent from the
80  * host computer to the Arduino.
81  * @until }
82  *
83  * Next comes the main loop function. Here we read a one line command from
84  * the host computer and decide what to do. There are only three commands
85  * defined:
86  * - One to turn all of the LEDs off.
87  * - One to set the aspect of one signal.
88  * - And a final command to initiate a test sequence.
89  *
90  * @until End of Main loop
91  *
92  * @section wiring Wiring the signals.
93  * I used this color coding for the signal LEDs when I wired them:
94  *
95  * <dl><dt>Green</dt><dd>The upper target head's green LED (uppermost LED of the upper target).</dd>
96  * <dt>Yellow</dt><dd>The upper target head's yellow LED (middle LED of the upper target).</dd>
97  * <dt>Red</dt><dd>The upper target head's red LED (bottom LED of the upper target).</dd>
98  * <dt>Blue</dt><dd>The lower target head's green LED (uppermost LED of the lower target).</dd>
99  * <dt>White</dt><dd>The lower target head's yellow LED (middle LED of the lower target).</dd>
100  * <dt>Black</dt><dd>The lower target head's red LED (bottom LED of the lower target).</dd>
101  * </dl>
102  *
103  * Thus the connections to the terminal blocks at the ends of the signal
104  * cables are made as shown here. If a target has fewer than three LEDs, then
105  * the wires for the missing LEDs are also missing.
106  *
107  * @image latex SignalConnectorBoard_ColorCodes.jpg "Signal Connector Board, Wiring Color Codes" width=4in
108  * @image html SignalConnectorBoard_ColorCodes-thumb.jpg "Signal Connector Board, Wiring Color Codes"
109  *
110  * Once you have entered the code and verified that it compiles and uploaded
111  * it to the Arduino, you can test the code with the Serial Monitor tool on
112  * the Arduino IDE. Be sure to set the baud rate to 115200. You can then type
113  * commands into the Serial Monitor tool's send bar, as shown here.
114  *
115  * @image latex SerialMonitor_TestSketch.png "Serial Monitor, Test Sketch" width=4.5in
116  * @image html SerialMonitor_TestSketch.png "Serial Monitor, Test Sketch"
117  * @htmlonly
118  * <div class="contents"><a class="el" href="ProgrammingtheHostComputer.html">Continuing with the Programming the Host Computer</a></div>
119  * @endhtmlonly
120  */
121 
122 #endif // __PROGRAMMINGTHEARDUINO_H
123