Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ItemCounter mit Savefunktion V.1.3 by redled72 5/2012
- cdel = ("right") -- Reset Counter (Button, Switch...)
- cin = ("left") -- Input Counter (RP-Signal, Redstonepipe...)
- sfile = "counter.txt" -- Filename Counterzaehlerstand
- local inp = false
- local s = 0
- local z = 0
- local stack = 0
- local stueck = 0
- local count = 0
- local wrt = 0
- function _dat() -- File anlegen/Standardwert
- h = fs.open(sfile, "w")
- h.write(0)
- h.close()
- end
- function _readdat() -- File oeffnen und erste Zeile lesen
- dat = fs.open(sfile, "r")
- zeile = dat.readLine()
- dat.close()
- return zeile
- end
- function _writedat(z) -- Fileinhalt ueberschreiben
- h = fs.open(sfile, "w")
- h.write(z)
- h.close()
- end
- function _wrtimer(z) -- periodisch speichern
- wrt = wrt + 1
- if wrt == 8 then
- _writedat(z)
- wrt = 0
- end
- end
- function _latch(inp) -- Counter
- if inp == true then
- count = count + 1
- while rs.getInput(cin) == inp do
- sleep(0.04)
- end
- else
- sleep(0.03)
- end
- if rs.getInput(cdel) == true then
- _dat()
- count = 0
- end
- return count
- end
- function _str(z) -- Stack/Stueckrechnung
- sta = math.floor(z / 64)
- stu = math.fmod(z, 64)
- return sta, stu
- end
- function _ascii()
- out = string.char(98,121,32,82,101,100,108,101,100,55,50)
- return out
- end
- if not fs.exists(sfile) then _dat() end
- count = _readdat()
- while s == 0 do -- Loop Hauptschleife
- inp = rs.getInput(cin)
- z = _latch(inp)
- _wrtimer(z)
- stack, stueck = _str(z)
- shell.run("clear")
- print("Counter Stueckzahl: " ..z.. " ")
- print("Anzahl in Stack : " ..stack.." & " ..stueck.. " Stueck")
- end
- print(newline)
- print("\"CC-ItemCounter\" " .._ascii().. "")
Advertisement
Add Comment
Please, Sign In to add comment