Last active
December 19, 2015 00:49
-
-
Save electricimp/5871309 to your computer and use it in GitHub Desktop.
Code to convert ADC readings to actual Voltage.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getPin9Voltage() | |
{ | |
// Returns value in volts, between 0.0 and 3.3 | |
local voltage = hardware.voltage(); | |
local reading = hardware.pin9.read(); | |
return (reading / 65535.0) * voltage; | |
} | |
function sample() | |
{ | |
server.log("The voltage on Pin 9 is:" + getPin9Voltage()); | |
imp.wakeup(1.0, sample); | |
} | |
// Set up imp Pin 9 as an analog input | |
hardware.pin9.configure(ANALOG_IN); | |
// Start sampling the voltage on Pin 9 | |
sample(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment