' Turntable selector
' ------------------
' Use UP/DN buttons to change value. Either button sets timer running
' Use SET button to set selected value. Only works during timer.
' When timer expires, display will change to working value.
' Adjust timeoutval to be about 3 seconds
' Use a two digit LED to show selection. ( Write code to suit )
' Symbols
symbol UPbtn = pinB.1 ' UP pushbutton
symbol DNbtn = pinB.2 ' DN pushbutton
symbol SETbtn = pinB.3 ' SET pushbutton
symbol valtemp = b4 ' Value changed by UP/DN buttons
symbol valwork = b5 ' Value selected by SET button
symbol LEDval = b6 ' Value to show on LEDs
symbol seltimer = w4 ' Timer for SET to be pressed
symbol stepsval = w5 ' Result of selection
symbol timeoutval = 30 ' Duration of SET timer, adjust to suit.
symbol TTsize = 48 ' Size of turntable
' Code starts here
' ----------------
do
if UPbtn = 1 then ' Count up
inc valtemp
if valtemp > TTsize then ' Rollover to bottom
valtemp = 1
endif
seltimer = timeoutval ' start timer
' pause 100 ' include a pause if count rate too fast
endif
if DNbtn = 1 then ' Count down
dec valtemp
if valtemp = 0 or valtemp = 255 then ' Rollover to top
valtemp = TTsize
endif
seltimer = timeoutval ' Start timer
' pause 100 ' include a pause if count rate too fast
endif
if seltimer > 0 then ' Timer is running
dec seltimer ' Decrement timer
LEDval = valtemp ' Display input value on LEDs
if SETbtn = 1 then ' SET button pressed
valwork = valtemp ' Copy valtemp to working
endif
else ' Timer is expired
LEDval = valwork ' Display working value on LED
' Bumpless changeover
if valwork > 0 then
valtemp = valwork ' Set valtemp to current working value
endif
endif
' DriveLEDs
' Put routine to drive LEDs here.
' LEDval is the digits. Add some fluff to show if timer running.
'
' Convert valwork to step count.First entry is not used.
' Change values to whatever each position requires.
' posn 1 2 3 etc ...
lookup valwork,(000,10,20,30,40,50,60,70,10,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240,250,260,270,280,290,300,310,320,330,340,350,360,370,380,390,400,410,420,430,440,450,460,470,480),stepsval
' Motor drive
if stepsval > 0 then ' only drive motor if a selection has been made
'
' Put motor drive stuff here
' sertxd ("motor ",#stepsval,cr,lf)
'
endif
' Diagnostics to serial
sertxd ("Temp : ", #valtemp, tab, "Work : ", #valwork,tab,"Time : ",#seltimer,tab,"LED :",#LEDval,tab,"Steps : ",#stepsval,cr,lf)
loop