Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.find("modem")
- local monitor = peripheral.find("monitor")
- local levels = {
- [0] = {percent = "0%", bgColor = colors.red, textColor = colors.white},
- [1] = {percent = "5%", bgColor = colors.red, textColor = colors.white},
- [2] = {percent = "10%", bgColor = colors.red, textColor = colors.white},
- [3] = {percent = "20%", bgColor = colors.red, textColor = colors.white},
- [4] = {percent = "25%", bgColor = colors.red, textColor = colors.white},
- [5] = {percent = "30%", bgColor = colors.yellow, textColor = colors.black},
- [6] = {percent = "40%", bgColor = colors.yellow, textColor = colors.black},
- [7] = {percent = "50%", bgColor = colors.yellow, textColor = colors.black},
- [8] = {percent = "55%", bgColor = colors.yellow, textColor = colors.black},
- [9] = {percent = "60%", bgColor = colors.green, textColor = colors.white},
- [10] = {percent = "70%", bgColor = colors.green, textColor = colors.white},
- [11] = {percent = "75%", bgColor = colors.green, textColor = colors.white},
- [12] = {percent = "80%", bgColor = colors.green, textColor = colors.white},
- [13] = {percent = "90%", bgColor = colors.green, textColor = colors.white},
- [14] = {percent = "95%", bgColor = colors.green, textColor = colors.white},
- [15] = {percent = "100%", bgColor = colors.green, textColor = colors.white},
- }
- term.clear()
- term.setCursorPos(1, 1)
- print("Running...")
- while not rs.getInput("front")
- do
- local level = rs.getAnalogInput("back")
- local batteryLevel = levels[level]
- term.setCursorPos(1, 3)
- term.clearLine()
- modem.transmit(4, 5, batteryLevel.percent)
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write("Battery")
- monitor.setCursorPos(3, 3)
- monitor.setBackgroundColor(batteryLevel.bgColor)
- monitor.setTextColor(batteryLevel.textColor)
- monitor.write(batteryLevel.percent)
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement