Scale-N

Scale-N
Arduino
Componenten
Rollend Materieel
Naslag
Onderdelen
Wissels
Basis Electronica
Symbols Electronica
Programming Arduino
AKS
DCC++
DR5000













































SENSORS

DCC++ BaseStation supports Sensor inputs that can be connected to any Aruidno Pin not in use by this program. Sensors can be of any type (infrared, magnetic, mechanical...). The only requirement is that when "activated" the Sensor must force the specified Arduino Pin LOW (i.e. to ground), and when not activated, this Pin should remain HIGH (i.e. 5V), or be allowed to float HIGH if use of the Arduino Pin's internal pull-up resistor is specified.
To ensure proper voltage levels, some part of the Sensor circuitry MUST be tied back to the same ground as used by the Arduino.
The Sensor code utilizes exponential smoothing to "de-bounce" spikes generated by mechanical switches and transistors. This avoids the need to create smoothing circuitry for each sensor. You may need to change the parameters in Sensor.cpp through trial and error for your specific sensors.
To have this sketch monitor one or more Arduino pins for sensor triggers, first define/edit/delete sensor definitions using the following variation of the "S" command:

< S ID PIN PULLUP >: Creates a new sensor ID, with specified PIN and PULLUP if sensor ID already exists, it is updated with specified PIN and PULLUP (You choose the number).
Returns: < O > if successful and < X > if unsuccessful (e.g. out of memory)
< S ID >: Deletes definition of sensor ID
Returns: < O > if successful and < X > if unsuccessful (e.g. ID does not exist)
< S >: Lists all defined sensors
Returns: < Q ID PIN PULLUP > for each defined sensor or if no sensors defined

ID: The numeric ID (0-32767) of the sensor
(You pick the ID & They ares shared between Turnouts, Sensors and Outputs)
PIN: The Arduino pin number the sensor is connected to on the Arduino board.
PULLUP: 1 = Use internal pull-up resistor for PIN, 0 = don't use internal pull-up resistor for PIN

Once all sensors have been properly defined, use the < E > (upper case E) command to store their definitions to EEPROM.
If you later make edits/additions/deletions to the sensor definitions, you must invoke the < E > (upper case E) command if you want those new definitions updated in the EEPROM.
You can also clear everything (turnouts, sensors, and outputs) stored in the EEPROM by invoking the < e > (lower case e) command.
(There is NO UN-Delete)

All sensors defined as per above are repeatedly and sequentially checked within the main loop of this sketch.If a Sensor Pin is found to have transitioned from one state to another, one of the following serial messages are generated:

< Q ID > - for transition of Sensor ID from HIGH state to LOW state (i.e. the sensor is triggered)
< q ID > - for transition of Sensor ID from LOW state to HIGH state (i.e. the sensor is no longer triggered)

Depending on whether the physical sensor is acting as an "event-trigger" or a "detection-sensor," you may decide to ignore the < q ID > return and only react to < Q ID > triggers.