Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- scanner = peripheral.wrap("right")
- function isBookPresent(scperiph)
- if scanner.getPageCount() == 0 then
- print("no book found")
- return false
- else
- print("book is inside scanner")
- return true
- end
- end
- function scanBook(scperiph)
- local pgNum
- local ycoor
- local xcoor
- local symChar
- local cnt = scperiph.getPageCount()
- local x, y = scperiph.getPageSize()
- print("--- SCANNING NEW BOOK ---")
- print("Book:"..scperiph.getTitle())
- for pgNum = 1, cnt do
- print("Page #"..pgNum)
- for ycoor = 1, y do
- for xcoor = 1, x do
- symChar = scperiph.getChar(xcoor,ycoor,pgNum)
- if symChar ~= "" and symChar ~= nil then
- write(symChar)
- end
- end
- if scperiph.getChar(1, ycoor, pgNum) ~= "" then
- print()
- end
- end
- end
- end
- function ejectBook()
- -- send pulse to autarchic gate to extract a book from scanner
- rs.setBundledOutput("back", colors.white)
- sleep(1.5)
- rs.setBundledOutput("back", 0)
- end
- function suckupBook()
- -- send pulse to manipulator to send a book
- rs.setBundledOutput("back", colors.orange)
- sleep(0.5)
- rs.setBundledOutput("back", 0)
- end
- function cycleBook()
- if isBookPresent(scanner) then
- scanBook(scanner)
- ejectBook()
- suckupBook()
- else
- suckupBook()
- end
- end
- while true do
- print("cycle step...")
- cycleBook()
- sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment