Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ESP8266 Servo TextLCD mbed
Fork of ACS712HelloWorldDemo by
ACS712.h
- Committer:
- nyengele
- Date:
- 2016-03-13
- Revision:
- 2:2b5233355986
- Parent:
- 1:4f9effb20c29
- Child:
- 3:9cae7baf7ccd
File content as of revision 2:2b5233355986:
#include <mbed.h> class ACS712 { public: ACS712(PinName _pin, float voltDivRatio = 1, short type = 5); float read(); float operator=(ACS712&); operator float() { return read(); } private: AnalogIn sensor; float translate(float); float ratio; short type; }; ACS712::ACS712(PinName _pin, float voltDivRatio, short type) : sensor(_pin){ ratio = voltDivRatio; this.type = type; } float ACS712::translate(float val){ switch(type){ case 5: return (val*ratio - 2.5*ratio)/(.185*ratio); break; case 20: return (val*ratio - 2.5*ratio)/(.1*ratio); break; case 30: return (val*ratio - 2.5*ratio)/(.066*ratio); break; default: return 999; break; } } float ACS712::read(){ return ACS712::translate(sensor * 3.3); } ACS712& ACS712::operator=(ACS712& rhs){ sensor = rhs.sensor; ratio = rhs.ratio; type = rhs.type; return this; }