项目作者: YuriiSalimov

项目描述 :
[For Arduino] Library for working with digital and analog sensors.
高级语言: C++
项目地址: git://github.com/YuriiSalimov/AD_Sensors.git
创建时间: 2018-02-05T23:27:42Z
项目社区:https://github.com/YuriiSalimov/AD_Sensors

开源协议:MIT License

下载


Analog-Digital Sensors Library

For Arduino boards.

The Library implements a set of methods for working with digital and analog sensors.

Installation

  1. Download the Latest release from GitHub.
  2. Unzip and modify the Folder name to “AD_Sensors” (Remove the ‘-version’)
  3. Paste the modified folder on your Library folder
    (On your libraries folder inside Sketchbooks or Arduino software).
  4. Restart the Arduino IDE.

Analog Sensor

Describes a set of methods for working with an analog sensor.

  1. #include <AnalogSensor.h>
  2. /**
  3. ANALOG_PIN - an analog port number that
  4. is attached to the sensor.
  5. */
  6. AnalogSensor* sensor = new AnalogSensor(ANALOG_PIN);
  7. /**
  8. Reads and return a signal from the analog sensor,
  9. from an analog port.
  10. */
  11. int value = sensor->read();

Digital Sensor

Describes a set of methods for working with a digital sensor.

  1. #include <DigitalSensor.h>
  2. /**
  3. DIGITAL_PIN - a digital port number that
  4. is attached to the sensor.
  5. */
  6. DigitalSensor* sensor = new DigitalSensor(DIGITAL_PIN);
  7. /**
  8. If you need to invert a sensor signal:
  9. INVERT_SIGNAL:
  10. true - invert a signal;
  11. false - not invert a signal.
  12. */
  13. DigitalSensor* sensor = new DigitalSensor(DIGITAL_PIN, INVERT_SIGNAL);
  14. /**
  15. Reads and return a signal from the digital sensor
  16. (0 or 1, 0 == LOW, 1 == HIGH).
  17. */
  18. int value = sensor->read();
  19. /**
  20. Checks a signal on the digital sensor,
  21. on the digital port.
  22. Returns true if the sensor signal is high,
  23. false - otherwise.
  24. */
  25. boolean value = sensor->isHigh();
  26. /**
  27. Checks a signal on the digital sensor,
  28. on the digital port.
  29. Returns true if the sensor signal is low,
  30. false - otherwise.
  31. */
  32. boolean value = sensor->isLow();

Average Sensor

Reads a signal from a origin sensor,
averages the signal and return it.

  1. #include <Sensor.h>
  2. #include <AnalogSensor.h>
  3. #include <AverageSensor.h>
  4. Sensor* origin = new AnalogSensor(ANALOG_PIN);
  5. /**
  6. COUNTER - number of readings;
  7. DELAY_TIME - delay time between readings.
  8. */
  9. Sensor* sensor = new AverageSensor(origin, COUNTER, DELAY_TIME);
  10. /**
  11. Returns the average signal value.
  12. */
  13. int value = sensor->read();

Smooth Sensor

Reads a signal from a origin sensor,
smoothes (moving average, rolling average or running average)
the signal and return it.

  1. #include <Sensor.h>
  2. #include <AnalogSensor.h>
  3. #include <SmoothSensor.h>
  4. Sensor* origin = new AnalogSensor(ANALOG_PIN);
  5. /**
  6. SMOOTHING_FACTOR - smoothing factor of readings (0 = not smooth).
  7. */
  8. Sensor* sensor = new SmoothSensor(origin, SMOOTHING_FACTOR);
  9. /**
  10. Return the average signal value.
  11. */
  12. int value = sensor->read();

Map Sensor

Reads a signal from a origin sensor, maps the signal and return it.
Re-maps the signal from one range to another.
That is, a signal of fromLow would get mapped to toLow,
a signal of fromHigh to toHigh, signals in-between to signals in-between, etc.

  1. #include <Sensor.h>
  2. #include <AnalogSensor.h>
  3. #include <MapSensor.h>
  4. Sensor* origin = new AnalogSensor(ANALOG_PIN);
  5. /**
  6. FROM_LOW - the lower bound of the value’s current range;
  7. FROM_HIGH - the upper bound of the value’s current range;
  8. TO_LOW - the lower bound of the value’s target range;
  9. TO_HIGH - the upper bound of the value’s target range.
  10. */
  11. Sensor* sensor = new MapSensor(
  12. origin,
  13. FROM_LOW, FROM_HIGH,
  14. TO_LOW, TO_HIGH
  15. );
  16. /**
  17. Returns the mapped signal value.
  18. */
  19. int value = sensor->read();

Constrain Sensor

Reads a signal from a origin sensor,
constrains the signal and return it.

  1. #include <Sensor.h>
  2. #include <AnalogSensor.h>
  3. #include <ConstrainSensor.h>
  4. Sensor* origin = new AnalogSensor(ANALOG_PIN);
  5. /**
  6. LOW - the lower end of the constraint range;
  7. HIGH - the upper end of the constraint range.
  8. */
  9. Sensor* sensor = new ConstrainSensor(origin, LOW, HIGH);
  10. /**
  11. Returns the constrained signal value.
  12. */
  13. int value = sensor->read();

See examples

Created by Yurii Salimov.