This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
X3ME's profile picture

Electric Counter

Started by X3ME, 09 September 2014 - 07:49 PM
X3ME #1
Posted 09 September 2014 - 09:49 PM
Hi,
I am looking for a bit complex program that can count redstone pluses infinitly and dyspla the count on screen:
For eitch redpulse it adds one…

Thanks,
Agent Silence #2
Posted 09 September 2014 - 10:03 PM

for i,v in pairs(rs.getSides()) do
if peripheral.isPresent(v) == true and peripheral.getType(v) == "monitor" then
  side = v
end
end
local function centerText(text)
local x,y = p.getSize()
local x2,y2 = p.getCursorPos()
p.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
write(text)
end
p = peripheral.wrap(side)
pulses = 0
while true do
for i,v in pairs(rs.getSides()) do
if rs.getInput(v) then
pulses = pulses + 1
p.clear()
centerText("Pulses : "..pulses)
end
end
end

sorry for the mess
X3ME #3
Posted 09 September 2014 - 10:05 PM

for i,v in pairs(rs.getSides()) do
if peripheral.isPresent(v) == true and peripheral.getType(v) == "monitor" then
  side = v
end
end
local function centerText(text)
local x,y = p.getSize()
local x2,y2 = p.getCursorPos()
p.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
write(text)
end
p = peripheral.wrap(side)
pulses = 0
while true do
for i,v in pairs(rs.getSides()) do
if rs.getInput(v) then
pulses = pulses + 1
p.clear()
centerText("Pulses : "..pulses)
end
end
end

sorry for the mess

Can you make it so that there is no monitor and the redstone input is bottom?

Thanks so much :D/>!
KingofGamesYami #4
Posted 09 September 2014 - 10:34 PM
This isn't that hard if you don't center the text.

local count = 0
while true do
 os.pullEvent( "redstone" )
 if rs.getInput( "bottom" ) then
  count = count + 1
 end
 term.clear()
 term.setCursorPos( 1, 1 )
 term.write( "Pulses: " .. count )
end