Guest User

CC Scanner code

a guest
Jun 21st, 2013
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.51 KB | None | 0 0
  1. scanner = peripheral.wrap("right")
  2.  
  3. function isBookPresent(scperiph)
  4.     if scanner.getPageCount() == 0 then
  5.         print("no book found")
  6.         return false
  7.     else
  8.         print("book is inside scanner")
  9.         return true
  10.     end
  11. end
  12.  
  13. function scanBook(scperiph)
  14.     local pgNum
  15.     local ycoor
  16.     local xcoor
  17.     local symChar
  18.     local cnt = scperiph.getPageCount()
  19.     local x, y = scperiph.getPageSize()
  20.     print("--- SCANNING NEW BOOK ---")
  21.     print("Book:"..scperiph.getTitle())
  22.     for pgNum = 1, cnt do
  23.       print("Page #"..pgNum)
  24.       for ycoor = 1, y do
  25.         for xcoor = 1, x do
  26.           symChar = scperiph.getChar(xcoor,ycoor,pgNum)
  27.           if symChar ~= "" and symChar ~= nil then
  28.             write(symChar)
  29.           end
  30.         end
  31.         if scperiph.getChar(1, ycoor, pgNum) ~= "" then
  32.             print()
  33.         end
  34.       end
  35.     end
  36. end
  37.  
  38. function ejectBook()
  39.     -- send pulse to autarchic gate to extract a book from scanner
  40.     rs.setBundledOutput("back", colors.white)
  41.     sleep(1.5)
  42.     rs.setBundledOutput("back", 0)
  43. end
  44.  
  45. function suckupBook()
  46.     -- send pulse to manipulator to send a book
  47.     rs.setBundledOutput("back", colors.orange)
  48.     sleep(0.5)
  49.     rs.setBundledOutput("back", 0)
  50. end
  51.  
  52. function cycleBook()
  53.     if isBookPresent(scanner) then
  54.         scanBook(scanner)
  55.         ejectBook()
  56.         suckupBook()
  57.     else
  58.         suckupBook()
  59.     end
  60. end
  61.  
  62. while true do
  63.     print("cycle step...")
  64.     cycleBook()
  65.     sleep(5)
  66. end
Advertisement
Add Comment
Please, Sign In to add comment