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

Redstone TouchScreen

Started by RealOhMand, 04 January 2016 - 12:07 AM
RealOhMand #1
Posted 04 January 2016 - 01:07 AM
Hello, Mr. and Mrs. Pro players! I ask for some help from you guys. I cant seem to find how to get a touchscreen monitor to have a button to change a redstone strength/ output a signal. I am currently on Tech World 2 1.6.4 FTB, just incase that is important. I just cant find a article or a code that i can get to work. My project is to get a trainstation that has a button that can activate a rail that can send it out. Thanks for reading!
KingofGamesYami #2
Posted 04 January 2016 - 01:15 PM
How about a tutorial?
Obsidia #3
Posted 04 January 2016 - 02:54 PM
Hey!

You'll want to use the "touchpoint API"! — http://www.computerc...touchpoint-api/ This one.

Get into your computer and type: pastebin get pFHeia96 touchpoint — This will download the touchpoint API

now go into your program ( edit PROGRAMNAME // mostlikely "edit startup" )

Now heres some code that should do the trick:

os.loadAPI("touchpoint")
local t = touchpoint.new("top")	-- Change it to your monitor side!
-- Your buttons!!
t:add("button1", nil, 2, 2, 10, 4, colors.red, colors.lime)
t:add("button2", nil, 2, 6, 10, 8, colors.red, colors.lime)
-- "button1/2" are the button names. Nil are the functions and the numbers are
-- the coordinates for your buttons. First color is the "Offline color" and the second one the
-- "Online color"
t:draw()   -- This will draw the buttons on to your monitor

while true do			  -- Heres where the magic happens.
  local event, button = t:handleEvents(os.pullEvent())
  if event == "button_click" then
		if button == "button1" then		  -- Tells what to do if you press the "button1" on your monitor
		  print("button1 was pressed")
		  t;toggleButton("button1")	
		elseif button == "button2" then          -- Tells what to do if you press the "button2" on your monitor
		  print("button2 was pressed")
		  t:toggleButton("button2")
		end
  end
end

To change redstone states:
rs.setOutput("SIDE", true/false)
for example: If you want to set the Redstone output on the right to 1 / On / true write:

rs.setOutput("right", true)

.. Oh if you would want to use bundled cable those work like this:

rs.setBundledOutput("SIDE", colors.COLOR)
- for example we want white to be on on the right side:
rs.setBundledOutput("right", colors.white)


Just tell me what you want exactly and I will write it for you as good as I can.
And yes my english is terrible but I hope I could help you somehow:p

have a nice day
Edited on 04 January 2016 - 02:04 PM
Dragon53535 #4
Posted 04 January 2016 - 05:04 PM
To change the redstone strength, from 0 to 15 blocks of power,

redstone.setAnalogOutput("right",15)
rs.setAnalogOutput("right",15)

As for the other bits of code, I'd follow the tutorial linked by KingofGamesYami.

If you're feeling more lazy, I'd do this with the touchpoint api listed in the previous post.
Spoiler

os.loadAPI("touchpoint")
local t = touchpoint.new("top") --#Change for monitor... top, bottom, left, right, front, back
local side = "right" --#Change for the side the redstone is on
local y = 0
for i =0,15 do
  t:add({tostring(i),label = "Button"..tostring(i)},function() rs.setAnalogOutput(side,i), 2+(2*i), 2+(2*y), 2+(2*i), 2+(2*y), colors.red, colors.lime)
  if i == 8 then
	y = 1
  end
end
t:toggleButton("Button0")
t.buttonList["Button0"].func()


local oldButton = "Button0"
while true do
  local event, button = t:handleEvents(os.pullEvent())
  if event == "button_click" then
	if button ~= oldButton then
	  t:toggleButton(oldButton)
	  t.buttonList[button].func()
	  t:toggleButton(button)
	  oldButton = button
	end
  end
end
Edited on 04 January 2016 - 04:04 PM
RealOhMand #5
Posted 04 January 2016 - 08:51 PM
Thanks!