m b
/
ACS712HelloWorldDemo
Demo of the ACS712 Library
Fork of ece4180_lab4_ACS712 by
Diff: ACS712.h
- Revision:
- 3:9cae7baf7ccd
- Parent:
- 2:2b5233355986
- Child:
- 4:f6c160553ca3
--- a/ACS712.h Sun Mar 13 16:51:20 2016 +0000 +++ b/ACS712.h Sun Mar 13 17:14:35 2016 +0000 @@ -1,12 +1,57 @@ #include <mbed.h> - +/** A Hall-Effect sensor for measuring current levels in a given path + * + * Can be used as a current detector + * + * Example: + * @code + * // Periodically read current levels in a circuit and + * // send output to PC terminal + * + * #include "mbed.h" + * #include "ACS712.h" + * + * // Connect the sensor analog output pin to mbed's AnalogIn pin + * ACS712 dev(p18); + * // Connect mbed to pc's USB port + * Serial pc(USBTX, USBRX); + * + * int main() { + * pc.printf("Sensor Log: \n\n\r"); + * while (1) { + * // Read current from sensor and output to pc terminal + * pc.printf("Sensor Value: %2.2f A\n\r", dev); + * wait(0.200); + * } + * } + * @endcode + */ + class ACS712 { public: + /** Create a hall-effect sensor of the specified type + * + * @param _pin mbed AnalogIn pin where the analog output of sensor is connected + * @param voltDivRatio resistor voltage division ratio at output of the sensor + * @param type type of ACS712 sensor used + * + * @note Supported types of sensors: + */ ACS712(PinName _pin, float voltDivRatio = 1, short type = 5); + /** Read the value of the measured current in amps + * + * @return current value in amps + */ float read(); float operator=(ACS712&); + + /** Read the value of the measured current in amps + * Allows the ACS712 object to be used in a float context + * + * @return current value in amps + */ operator float() { return read(); } private: