Skip to content

Instantly share code, notes, and snippets.

@avtehnik
Last active August 29, 2015 14:07
Show Gist options
  • Save avtehnik/5c021f6b4ea115d95c95 to your computer and use it in GitHub Desktop.
Save avtehnik/5c021f6b4ea115d95c95 to your computer and use it in GitHub Desktop.
math of acs712
http://www.mpja.com/download/ACS712.pdf
<div>vcc <input id="vcc" value="5" /></div>
<div>vout <input id="vout" value="4.5" /></div>
<div>result <input id="va"/></div>
<script>
var vcc = document.id('vcc');
var vout = document.id('vout');
var vat = document.id('va');
function acs712(vcc, vout, step){
if(!step){
step = 6.66666666667;
}
var result =((vout - (vcc/2))/ step)*100;
return result;// Math.round(result);
}
vout.addEvent('keyup',function(){
vat.value = acs712(parseFloat(vcc.value) ,parseFloat(vout.value) )
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment