when writing code, you have to have an idea what you want. if you have it firmly set, then it is easier to do.
in your case, you want to .
lower blade manually to set the first cut.
take the first cut
manually lower blade to take second cut.
take second cut. at this point you may or may not want to start slabbing, or roll the log.
so, there is a lot of manual stuff going on.
assume you have a cant with the desired width and are ready to start slabbling
( a cant is a square log after your took off the rounded bits, ideally one side is cut to the desired width and all you need to do is to take off slabs of the right thickness.)
since you just took off that last manual , you want to take a cut that is X thick.
that means drop the saw head by X plus blade cut thickness.
take a cut,
hit end switch
raise head by x + 1 inch
retract saw to start
lower head by x +1 inch to get back to the last cut
lower head by + plus blade,
take second cut, to end,
raise to 2x plus 1 inch - if you have not removed the boards
raise to 1x plus 1 inch if you had already removed the first board
raise to plus 1 inch if you have an automatic board pusher.
Lets assume that you set the encoder to be 0 at 1 inch over the deck.
all logs will be higher and you work from a high number down.
you still have to know the level of any dogs you set
you still have to set for your blade thickness after a change.
if you take your last manual cut and hit the end stop
LastCut = (whatever the encoder was showing when you hit the end stop)
say your cant is 16 inches
you take off 1.5 inch, hit the end stop
LastCut = 14.5
you lift to 17, retract, remove the last board
the head should drop to 13 as that would be ....
LastCut - button2 ; // button 2 is 1.5 inches
after your cut, hit that end switch
LastCut = 13
now, you still have to tell the Arduino how many counts = 1 inch
and instead of LastCut=13
it might be LastCut = 6656; // 1 inch is 512 encoder counts.
what becomes 'simpler than what the other guy did'
takes a whole lot for granted.
you will always remove the last board.....
you will always know the height of your dogs....
since you cannot plan for every possible need or want, the basics are not hard and you can do it.
as you start cutting, you might naturally want to add features.
my suggestion is that you create a bench setup with a second Arduino.
do all your testing on that one, and then once you think it is working, reprogram the one on the mill.