View difference between Paste ID: wLuE5H5N and JbdiLEZw
SHOW: | | - or go back to the newest paste.
1
local radar, currentSecond, lastInput = peripheral.wrap('radar_0'), 0, 0
2
3
function initiate()
4
	while true do
5
		loop()
6
		currentSecond = currentSecond + 1
7
		sleep(1)
8
	end
9
end
10
11
function loop()
12
	-- Every 2 Seconds to reduce amount of sensor calls and potentially limit lag
13
	if ( currentSecond % 1 == 0 ) then
14
		-- Probe Sensors
15
print('starting second')		
16
local isInside
17
print('checking radar')
18
  local players = radar.getPlayers()
19
  if ( type(players) ~= 'table' ) then
20
  return
21
  end
22
		for index, player in ipairs(players) do
23
			if ( player.distance < 5.5 ) then
24
print('found player '..player.name)				
25
isInside = true
26
			end
27
		end
28
  local power = (isInside and 0 or math.random(5,15))
29
print('ended radar')
30
print('setting state of output to '..tostring(not isInside))
31-
if ( lastInput ~= not isInside ) then
31+
if ( lastInput ~= isInside ) then
32
	term.setCursorBlink(true)
33
    rs.setAnalogOutput('right', power)
34-
  lastInput = (not isInside)
34+
	term.setCursorBlink(false)
35
  print('completed state change '..tostring(not isInside)..':'..tostring(rs.getOutput('right')))
36
  lastInput = isInside
37
end
38
term.setCursorBlink(not isInside)
39
	end	
40
end
41
42
initiate()