Note: This is in Feed The beast mod, Requires ComputerCraft and RailCraft mods.

I have coded a signal and point visualizer for Advanced computers in Computer craft to display what state points and signals are on a line. I made this for a automated system me and someone else is trying to do on a FTB server.

Points view: (click to view bigger)

computer view: (click to view bigger)

Video: (uploading)

The code:

————
All files must be saved as “startup” in the computer, once code is entered reboot the PC and it will automatically start.
————

This first bit is for computers by signal receiver boxes, you need to change the redstone.getInput(“side”) to the side that the receiver is on (must be connected) also you need to change the rednet.open(“side”) to where the wireless modem is attached, the last thing to change is the ID, this needs to be the ID of the advanced computer where the map will be displayed.

function clear()
  term.clear()
  term.setCursorPos(1,1)
end

rednet.open("right")
id = 19
print("debug: start") 

while true do
  os.pullEvent("redstone")
  rs = redstone.getInput("bottom")
  print("debug: loop start")

  if rs == true then
    clear()
    print("green")
    rednet.send(id, "green")
  else
    clear()
    print("red")
    rednet.send(id, "red")
  end
end

This next part if for computers controlling points, again change the rednet.open(“side”) , the ID and the rs.setOutput(“side”… to the side the redstone is going to the points.

rednet.open("right")

while true do
  event, id, msg, dist = os.pullEvent("rednet_message")
  id = 19

  if msg == "on" then
    rs.setOutput("top", true)
    rednet.send(id, "on")
  else
    rs.setOutput("top", false)
    rednet.send(id, "off")
  end
end

This next part is for the advanced computer itself, On this you need to have 4 images saved on the PC using the Paint program called red, green, pred and pgreen. First on the code you need to change/add/remove the image veriables, the number in the brackets is the ID of the computer the message is receive from, change these to what you have. To custimize the map you need to change the DrawLine commands under the “Function drawLines()” they are done like this, paintutils.drawLine(start x, start y, end x, end y, colour). The draw image commands are there as the images wont display on start-up in-till a message is received. Next change the Rednet.open again. On the while true loop you need to change the ID’s to the Signal and Point computers also changing the fucntion call command to “point” or “signal” depending on the ID’s type, The X and Y is where the image will be placed on the screen.

-- images
pointon = {}
pointoff = {}
red = {}
green = {}
pointon[16] = paintutils.loadImage("red")
pointoff[16] = paintutils.loadImage("green")
pointon[17] = paintutils.loadImage("red")
pointoff[17] = paintutils.loadImage("green")
pointon[21] = paintutils.loadImage("red")
pointoff[21] = paintutils.loadImage("green")
red[24] = paintutils.loadImage("pred")
green[24] = paintutils.loadImage("pgreen")
red[25] = paintutils.loadImage("pred")
green[25] = paintutils.loadImage("pgreen")
red[26] = paintutils.loadImage("pred")
green[26] = paintutils.loadImage("pgreen")
pointon[28] = paintutils.loadImage("red")
pointoff[28] = paintutils.loadImage("green")

--

function drawLines()
  term.clear()
  term.setCursorPos(1,1)
  paintutils.drawLine(2, 4, 49, 4, 128)
  paintutils.drawLine(2, 8, 49, 8, 128)
  paintutils.drawLine(28, 8, 28, 20, 128)
  paintutils.drawLine(22, 8, 22, 20, 128)
  paintutils.drawLine(20, 4, 20, 12, 128)
  paintutils.drawLine(20, 12, 22, 12, 128)
  paintutils.drawLine(30, 4, 30, 12, 128)
  paintutils.drawLine(28, 12, 30, 12, 128)
  paintutils.drawLine(45, 4, 45, 0, 128)
  paintutils.drawImage(pointoff[21], 30, 4)
  paintutils.drawImage(pointoff[16], 28, 8)
  paintutils.drawImage(pointoff[17], 22, 12)
  paintutils.drawImage(pointoff[28], 45, 4)
  paintutils.drawImage(green[24], 20, 16)
  paintutils.drawImage(green[25], 32, 7)
  paintutils.drawImage(green[26], 13, 2)
end

function signal(id, msg, x, y)
	if msg == "green" then
		paintutils.drawImage(green[id], x, y)
	else
		paintutils.drawImage(red[id], x, y)
	end
end

function point(id, msg, x, y)
	if msg == "on" then
		paintutils.drawImage(pointoff[id], x, y)
	else
		paintutils.drawImage(pointon[id], x, y)
	end
end

rednet.open("top")
drawLines()

while true do
  event, id, msg, dist = os.pullEvent("rednet_message")
  if id == 16 then
	x = 28
	y = 8
	point(id, msg, x, y)  
  elseif id == 17 then
    x = 22
	y = 12
	point(id, msg, x, y)  
  elseif id == 21 then
    x = 30
	y = 4
	point(id, msg, x, y) 
  elseif id == 24 then
    x = 20
	y = 16
	signal(id, msg, x, y) 	
  elseif id == 25 then
    x = 32
	y = 7
	signal(id, msg, x, y) 	
  elseif id == 26 then
    x = 13
	y = 2
	signal(id, msg, x, y) 
  elseif id == 28 then
    x = 45
	y = 4
	point(id, msg, x, y) 	
  else
    drawLines()
  end
end

 


Leave a Reply

Your email address will not be published.