lego11

Porta a Pagamento

May 11th, 2018
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function clear()
  2. term.clear()
  3. term.setCursorPos(1,1)
  4. end
  5.  
  6. m = peripheral.wrap("right") --magcard
  7. lbl = "BN Credit"
  8. print("Porta a Pagamento(R)")
  9. print("")
  10. print("Inserire la carta")
  11. m.setInsertCardLight(true)
  12. za,rawCredito = os.pullEvent("mag_swipe")
  13. m.setInsertCardLight(false)
  14. credito = tonumber(rawCredito)
  15. while true do
  16. print("La carta ha una disponibilità di "..credito.." IC.")
  17. print("")
  18. print("Per favore scegliere un'opzione utilizzando i tasti numerici e confermare con ENTER:")
  19. print("")
  20. print("[1] Aprire la porta - Costo: 2 IC")
  21. print("[2] Annullare il pagamento")
  22. num=tonumber(read())
  23. if num == 1 then
  24. prelievo=2
  25. if prelievo > credito then
  26. clear()
  27. print("Disponibilità insufficiente")
  28. sleep(5)
  29. os.reboot()
  30. end
  31. clear()
  32. print("Inserire nuovamente la carta per confermare il pagamento")
  33. nuovoCredito = credito - prelievo
  34. ncr = tostring(nuovoCredito)
  35. m.setInsertCardLight(true)
  36. m.beginWrite(ncr,lbl)
  37. os.pullEvent("mag_write_done")
  38. m.setInsertCardLight(false)
  39. print("Porta perta")
  40. print("")
  41. redstone.setOutput("bottom", true)
  42. sleep(5)
  43. redstone.setOutput("bottom", false)
  44. print("")
  45. print("Grazie!")
  46. sleep(5)
  47. os.reboot()
  48. elseif num == 2 then clear() break end
  49. end
  50. clear()
  51. print("Attendere")
  52. sleep(1)
  53. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment