local monitor  = peripheral.wrap("right")
local modem = peripheral.wrap("back")
local outChannel = 666
local inChannel = 667
modem.open(outChannel)
monitor.setTextScale(0.5)
monitor.clear()
modem.transmit(outChannel, inChannel, "won")
modem.transmit(outChannel, inChannel, "lon")
modem.transmit(outChannel, inChannel, "sclose")
drop = false
water = true
light = true
door = true
function updateMonitor()
  monitor.clear()
  monitor.setCursorPos(1,1)
  monitor.write("Grinder Status")
  monitor.setCursorPos(1,2)
  monitor.write("drop:"..tostring(drop))
  monitor.setCursorPos(1,3)
  monitor.write("Door:"..tostring(door))
  monitor.setCursorPos(1,4)
  monitor.write("Water:"..tostring(water))
  monitor.setCursorPos(1,5)
  monitor.write("Light:"..tostring(light))
end
function printMenu()
  term.clear()
  term.setCursorPos(1,1)
  print("Grinder Control")
  print("---------------")
  print("1: Close drop")
  print("2: Open drop")
  print("3: Turn on light")
  print("4: Turn off light")
  print("5: Turn on water")
  print("6: Turn off water")
  print("7: Open door")
  print("8: Close door")
  io.write(">")
end
while true do
  updateMonitor()
  printMenu()
  local a
  a = io.read()
  if a == "1" then
    redstone.setOutput("bottom", true)
    drop = true
  end
  if a == "2" then
    redstone.setOutput("bottom",false)
    drop = false
  end
  if a == "3" then
    shell.run("lon")
    light = true
  end
  if a == "4" then
    shell.run("loff")
    light = false
  end
  if a == "5" then
    shell.run("won")
    water = true
  end
  if a == "6" then
    shell.run("woff")
    water = false
  end
  if a == "7" then
    shell.run("sopen")
    door = true
  end
  if a == "8" then
    shell.run("sclose")
    door = false
  end
  if a == "9" then
    shell.run("on")
  end
end
