Lua script - collection data and save into a file -


i working on coding lua script.

what coding is..collecting data , save file.

situation :
there 2 sensors when recognize object in front of it, value of sensor increased.
want save data of value of sensor every 100ms time.
time format "2013-04-25 10:30:004"

what did here.

===========================================================  require("timer") require("timestamp") require("analog_in")  function onexit()     print("exit code...do something") end  function main()      timer = "timer"     analogsensor_1 = "air_1"     analogsensor_2 = "air_2"      while true          valueofsensor_1 = analog_in.readanalogin(analogsensor_1);         valueofsensor_2 = analog_in.readanalogin(analogsensor_2);          write(colltection_of_data.txt)         go(print(valueofsensor_1), 0.1)     //print value of sensor every 100ms         print(time)         go(print(valueofsensor_2), 0.1)         print(time)     end      timer.sleep(timer,500)  end   print("start main") main()  ================================================================ 

i know it's not complete code. how can save data file? , how can show time format that?

thank in advance!

sorry, no fractional seconds

-- open file local file = assert(io.open('collection_of_data.txt','wb'))  -- write file local dt = os.date'*t' local time_string =     dt.year..'-'..('0'..dt.month):sub(-2)..'-'..('0'..dt.day):sub(-2)..' '..    ('0'..dt.hour):sub(-2)..':'..('0'..dt.min):sub(-2)..':'..('0'..dt.sec):sub(-2) file:write(valueofsensor_1, '\n', time_string, '\n')  -- close file file:close() 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -