Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("top")
- mon = peripheral.wrap("left")
- mon.clear()
- os.sleep(2)
- knappNummer = 1
- knapper= {}
- print(os.getComputerID())
- fre = false
- function knapp(navn, func, status, xmin, xmax, ymin, ymax)
- knapper[knappNummer]={}
- if status == "true" then
- knapper[knappNummer]["status"] = true
- else
- knapper[knappNummer]["status"] = false
- end
- knapper[knappNummer]["navn"] = navn
- knapper[knappNummer]["func"] = func
- knapper[knappNummer]["xmin"] = xmin
- knapper[knappNummer]["xmax"] = xmax
- knapper[knappNummer]["ymin"] = ymin
- knapper[knappNummer]["ymax"] = ymax
- knappNummer=knappNummer+1
- end
- function ventPaEvent()
- event, param1, param2, param3 = os.pullEvent()
- if event == "monitor_touch" then
- checkxy(param2, param3)
- print("nice")
- elseif event == "rednet_message" then
- else
- print("feil event")
- end
- end
- function checkxy(x, y)
- for z=1, #knapper do
- if x>=knapper[z]["xmax"] and x<=knapper[z]["xmin"] then
- if y>=knapper[z]["ymax"] and y<=knapper[z]["ymin"] then
- knapper[z]["func"]()
- fre = not fre
- tegn(fre)
- print("bra")
- end
- end
- end
- end
- function tegn(d)
- mon.setBackgroundColor(colours.black)
- mon.clear()
- if d then mon.setBackgroundColor(colors.lime)
- else mon.setBackgroundColor(colors.red) end
- for zz=1, #knapper do
- zy=knapper[zz]["ymin"]
- for zx=knapper[zz]["xmin"], knapper[zz]["xmax"] do
- mon.setCursorPos(zx, zy)
- mon.write(" ")
- for zy=zy, knapper[zz]["ymax"] do
- mon.setCursorPos(zx, zy)
- mon.write(" ")
- end
- end
- mon.setCursorPos(knapper[zz]["xmin"]+1, knapper[zz]["ymax"]-1)
- mon.write(knapper[zz]["navn"])
- end
- end
- function en() print("bra funksjon") end
- knapp("en", en, false, 1, 10, 1, 10)
- tegn()
- while true do ventPaEvent() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement