Created
April 26, 2021 02:23
-
-
Save futureshocked/01f4d182ababa112216d68fb6ea112d3 to your computer and use it in GitHub Desktop.
This program demonstrates how to use a formula to scale the voltage measured on AIN0.
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
--[[ | |
LJ - 09.100 - convert_AIN_with_function.lua | |
This program demonstrates how to use a formula to scale the voltage | |
measured on AIN0. | |
Components | |
---------- | |
- LabJack T4 | |
- Potentiometer | |
- Midlle pin to AIN0 | |
- Left pin to VS | |
- Right pin to GND | |
- Wires | |
- Breadboard | |
Course | |
------ | |
Data acquisition and automation with LabJack | |
https://app.techexplorations.com/courses/labjack/ | |
--]] | |
-- If we are not running on a T4, stop the script. | |
devType = MB.R(60000, 3) | |
if devType ~= 4 then | |
print("Device is not a T4") | |
MB.W(6000, 1, 0); | |
end | |
-- Set up a 1 second timer | |
LJ.IntervalConfig(0, 1000) | |
-- define used variables. | |
local ainVal = 0 | |
local dacVal = 0 | |
function convert_ain(ain_value) | |
return ain_value * 1.5 | |
end | |
-- Enter a permanent while loop | |
while true do | |
if LJ.CheckInterval(0) then -- Interval completed. | |
-- Read AIN0 | |
ainVal = MB.R(0, 3) | |
-- Make sure the AIN0 value is between 0V and 5V | |
dacVal = ainVal | |
if(ainVal > 5) then | |
dacVal = 5 | |
end | |
if(ainVal < 0) then | |
dacVal = 0 | |
end | |
-- Convert value (voltage) from AIN0 to something else based on a formula. | |
-- This simulates converting a thermocouple signal to temperature. | |
temp_C = convert_ain(ainVal) -- I've made up this formula | |
print("Temperature in C:", temp_C) | |
print("Voltage at AIN0:", ainVal) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment