#include "Sensor.h"
Public Member Functions | |
void | begin (int snum, int pin, int pullUp) |
void | set (int snum, int pin, int pullUp) |
boolean | isActive () |
Static Public Member Functions | |
static Sensor * | get (int snum) |
static void | remove (int snum) |
static int | count () |
static void | check () |
static void | load () |
static void | store () |
static void | parse (char *c) |
static Sensor * | create (int snum, int pin, int pullUp) |
Public Attributes | |
SensorData | data |
boolean | active |
float | signal |
Sensor * | nextSensor |
Static Public Attributes | |
static Sensor * | firstSensor =NULL |
DCC++ BASE STATION supports Sensor inputs that can be connected to any Arduino 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 (e.g. 5V), or be allowed to float HIGH if use of the Arduino Pin's internal pull-up resistor is specified. Be careful, don't use Arduino's internal pull-up resistors for external infrared sensors: each sensor must have its own 1K external pull-up resistor.
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 below 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 these parameters 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 one on the variation of the "S" command.
Once all sensors have been properly defined, use the <E> command to store their definitions to EEPROM. If you later make edits/additions/deletions to the sensor definitions, you must invoke the <E> command if you want those new definitions updated in the EEPROM. You can also clear everything stored in the EEPROM by invoking the <e> command.
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:
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.
void begin | ( | int | snum, |
int | pin, | ||
int | pullUp | ||
) |
Initialize the sensor created by regular C++ instantiation.
snum | The numeric ID (0-32767) of the sensor. |
pin | The arduino pin number to use for the sensor. |
pullUp | 1 = use internal pull-up resistor for pin, 0 = don't use internal pull-up resistor for pin. |
Definition at line 24 of file Sensor.cpp.
void set | ( | int | snum, |
int | pin, | ||
int | pullUp | ||
) |
Force the sensor values created by command line.
snum | The numeric ID (0-32767) of the sensor. |
pin | The arduino pin number to use for the sensor. |
pullUp | 1 = use internal pull-up resistor for pin, 0 = don't use internal pull-up resistor for pin. |
Definition at line 53 of file Sensor.cpp.
|
static |
Get a particular sensor.
snum | The numeric ID (0-32767) of the sensor. |
Definition at line 71 of file Sensor.cpp.
|
static |
Removes a particular sensor.
snum | The numeric ID (0-32767) of the sensor. |
Definition at line 78 of file Sensor.cpp.
|
static |
Get the total number of sensors.
Definition at line 110 of file Sensor.cpp.
|
static |
Checks if the associated pin is LOW or HIGH and update the 'signal' field with a pondered value.
Definition at line 120 of file Sensor.cpp.
boolean isActive | ( | ) |
|
static |
Load the content of this sensor from EEPROM.
Definition at line 200 of file Sensor.cpp.
|
static |
Store the content of this sensor in EEPROM.
Definition at line 227 of file Sensor.cpp.
|
static |
Do command according to the given command string.
c | string to interpret... See syntax in class description. |
Definition at line 249 of file Sensor.cpp.
|
static |
Creates a new sensor in the list..
snum | The numeric ID (0-32767) of the sensor. |
pin | The arduino pin number to use for the sensor. |
pullUp | 1 = use internal pull-up resistor for pin, 0 = don't use internal pull-up resistor for pin. |
Definition at line 281 of file Sensor.cpp.
|
static |
SensorData data |