This script is reposted from the CHDK forum : Autoexposure Intervalometer
Save it as autoexp.lua
--[[
@title Intervalometer with auto Tv
@param n NumofShots
@default n 1000
@param d Delay
@default d 60
@param s Delay step (ms)
@default s 500
@param l Bv96 correction @ Bv = -500
@default i 0
@param h Bv96 correction @ Bv = +500
@default j 0
@param x Draw chart on screen? 0=No
@default x 1
@param p How many points?
@default p 100
--]]
--[[
This script is based on work of cyril42e (cyril42e@gmail.com)
http://crteknologies.fr/wiki/doku.php/photo:chdk-scripts#night_shot
(I used his way to calculate shutter time)
Changed to intervalometer and converted to Lua by Pawel Tokarz aka Outslider
Nice chart of brightness vs photo number added.
--]]
--initialize Bv chart
if (x ~= 0) then
NUMOF_POINTS=p
CHART_BV_STEP=1
CHART_BV={}
CHART_BV_LINE={}
CHART_X0=10
CHART_Y0=20
CHART_BV_MIN=nil
CHART_BV_MAX=nil
require "drawings"
draw.add("rectf",CHART_X0,CHART_Y0,CHART_X0+NUMOF_POINTS,CHART_Y0+50,"white","trans")
CHART_BV_MAX_LABEL=draw.add("string",CHART_X0,CHART_Y0-9,"minBV","white","black")
CHART_BV_MIN_LABEL=draw.add("string",CHART_X0,CHART_Y0+51,"maxBV","white","black")
i=0
for i=1, NUMOF_POINTS do
CHART_BV[i]=nil
CHART_BV_LINE[i]=draw.add("line",CHART_X0,CHART_Y0,CHART_X0,CHART_Y0,"blue")
end
end
set_console_layout(0,0,25,5)
set_console_autoredraw(0)
A=h-l
B=(l+h)/2
TV_OSD_TIME = 0
TV_OSD_96 = 0
BV_OSD = nil
BV_COR = 0
DELAY_OSD = 0
function chart_update()
if (x~=0) then
if (CHART_BV_MIN==nil) then CHART_BV_MIN=BV_OSD end
if (CHART_BV_MAX==nil) then CHART_BV_MAX=BV_OSD end
if (BV_OSD<CHART_BV_MIN) then CHART_BV_MIN=BV_OSD end
if (BV_OSD>CHART_BV_MAX) then CHART_BV_MAX=BV_OSD end
draw.replace(CHART_BV_MAX_LABEL,"string",CHART_X0+2,CHART_Y0-11,"Bv max: "..CHART_BV_MAX,"white","black")
draw.replace(CHART_BV_MIN_LABEL,"string",CHART_X0+2,CHART_Y0+49,"Bv min: "..CHART_BV_MIN,"white","black")
CHART_BV[NUMOF_POINTS]=BV_OSD
for i=1, NUMOF_POINTS-1 do
CHART_BV[i]=CHART_BV[i+1]
if (CHART_BV[i] ~= nil ) then
y=CHART_Y0+50-((CHART_BV[i]-CHART_BV_MIN)*50/(CHART_BV_MAX-CHART_BV_MIN))
draw.replace(CHART_BV_LINE[i],"line",CHART_X0+i,y,CHART_X0+i,CHART_Y0+50,"white")
end
end
draw.overdraw()
end
end
function OSD_update()
if (x ~= 0) then
draw.overdraw()
end
print("Brightness : "..BV_OSD)
print("Correction : "..BV_COR)
print("Tv : "..TV_OSD_TIME)
print("Tv (96) : "..TV_OSD_96)
print("Delay : "..DELAY_OSD)
end
shoots_done=0
repeat
loop_step_start_time=get_tick_count()
--Camera will get exposure parameters now
--This loop is complicated, since camera sometimes miss get_shooting.
--On my SX130 it happens once per a few thousands shots,
--but this is enough to break nice time-lapse video.
self_test=false
repeat
press("shoot_half") --we press shoot_half to get all exposure params
step=0
repeat
sleep(10)
if (get_shooting()) then --if we are lucky, camera can shoot now,
step=300 --so we set step>200 to leave safety loop
self_test=true --and set self_test to true to leave outside loop
end
step=step+1
until step>200
if(self_test==false) then --we had no luck this time, camera missed something,
release("shoot_half") --so we release shoot_half and go back.
end
until self_test==true
--we read Bv (luminance), Sv (ISO), Av (aperture), Ev shift and current Tv (exposure time)
Bv=get_bv96()
Sv=get_sv96()
Av=get_av96()
Ev=get_prop(207)
Tv=get_tv96() --useless, but in a case to modify this script in future
--we calculate and set new Tv (from APEX definitions)
Tv_new=Bv+Sv-Av-Ev
BV_COR=Bv*A/1000+B
Tv_new=Tv_new-BV_COR
if(Tv_new<0) then TV_OSD_TIME=2^(-Tv_new/96) end
if(Tv_new>0) then TV_OSD_TIME="1/"..2^(Tv_new/96) end
TV_OSD_96=Tv_new
BV_OSD=Bv
chart_update()
set_tv96_direct(Tv_new)
sleep(100)
release("shoot_half")
OSD_update()
sleep(100)
--And propably the most important command in this script
shoot()
OSD_update()
--wait appropriate time
repeat
time_to_wait=1000*d-get_tick_count()+loop_step_start_time
-- print("left: "..time_to_wait.." ms")
DELAY_OSD=time_to_wait/1000
OSD_update()
sleep(s)
until time_to_wait<s
--repeat for next shoot
shoots_done=shoots_done+1
until shoots_done==n