hey, I thought to add to the programs shown here, (and following Nassiel's example of showing of some code)
This program was written to control my nuclear outpost,
I'm playing with the apm nuclear mod, so I had multiple fuels to choose from. I choose to make a program that selects the highes amount type, and then check if steam is below a certain level (and going down)
setup:
green input = steam of boiler tanks & logistics network content
red input = constant combinator with fuels as content, this is the 'filter' to only check required items from the logistics network
output = a 1 pulse signals routed to filter inserters, they start the fuel cycle
! this program was way shorter (it fitted in <32 fCPU), but I added some comments to give context
I'm not sure if comment in the same line as the instruction works, so it might not be directly copy/past-able
clr ;cleanup for first run
:start
;cleanup counter, and max register
;r2=counter register, r3=max reg
clr r2 r3
:filterloop
inc r2
mov r1 red@2 ;get inputsignal from filter input @ counter(r2)
:inputloop
fig r1 r1 ;find this in green
tlt r3 r1 ;bigger than max reg? (first run of loop it always will)
swp r1 r3
tge r2 cnr ;counter > #signals in red(filter input)?
jmp :checkNext
jmp :filterloop
:checkNext
fig r1 [fluid=steam] ; get steam from input
tlt r1 r8 ; check steam with priv steam value (r8)
jmp :checkSteam
:endCheckSteam ;return label for steam check.
mov r8 r1 ;move current steam level to r8, and restart.
jmp :start
:checkSteam ; only active if steam is going down.
tlt r1 30000 ; my steam level setup is between 0-100k, so 30% was a good level
jmp :pulse
jmp :endCheckSteam
:pulse
ssv r3 1 ;set value of max register to 1 (external counting register counts how many time fcpu triggerd a fuel cycle)
mov out1 r3 ;'emmit fuel type'
clr out1 ;stop it directly, making 1 tick pulse
slp 3600 ;sleep some time to give the reactor time to heat back up and create steam.
jmp :endCheckSteam
Hope this helps picking some code out for your own projects. :)