local monitor  = peripheral.wrap("right")
local modem = peripheral.wrap("back")
local inChannel = 666
local outChannel = 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")
redstone.setOutput("bottom", false)
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("--------------")
  monitor.setCursorPos(1,3)
  if drop then 
    monitor.write("drop: closed")
  else
    monitor.write("drop: open")
  end
  monitor.setCursorPos(1,4)
  if door then
    monitor.write("Door: open")
  else
    monitor.write("Door: closed")
  end
  monitor.setCursorPos(1,5)
  if water then
    monitor.write("Water: on")
  else
    monitor.write("Water: off")
  end
  monitor.setCursorPos(1,6)
  if light then
    monitor.write("Light: on")
  else
    monitor.write("Light: off")
  end
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
    modem.transmit(outChannel, inChannel, "lon")
    light = true
  end
  if a == "4" then
    modem.transmit(outChannel, inChannel, "loff")
    light = false
  end
  if a == "5" then
    modem.transmit(outChannel, inChannel, "won")
    water = true
  end
  if a == "6" then
    modem.transmit(outChannel, inChannel, "woff")
    water = false
  end
  if a == "7" then
   modem.transmit(outChannel, inChannel, "sopen")
    door = true
  end
  if a == "8" then
    modem.transmit(outChannel, inChannel, "sclose")
    door = false
  end
  if a == "9" then
    --shell.run("on")
  end
end
