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:
- mikeb
- Date:
- 2016-03-09
- Revision:
- 0:a35011a2fdaa
- Child:
- 1:4f9effb20c29
File content as of revision 0:a35011a2fdaa:
#include <mbed.h> class ACS712 { public: ACS712(PinName _pin, float voltDivRatio = 1, short type = 5); float read(); float operator=(ACS712&); //void sampleInterval(float); //void sampleFrequency(float); //void bufferLength(int); //float[] readBuffer(); private: AnalogIn sensor; float translate(float); //float[] circularBuffer; //float interval; float ratio; short type; }; ACS712::ACS712(PinName _pin, float voltDivRatio, short type) : sensor(_pin){ ratio = voltDivRatio; 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); } float ACS712::operator=(ACS712& rhs){ return rhs.read(); }