SHOW:
|
|
- or go back to the newest paste.
1 | -- Valve, Monitor & Wireless Modem | |
2 | local val = peripheral.wrap("back") | |
3 | local mon = peripheral.wrap("top") | |
4 | local wmod = peripheral.wrap("bottom") | |
5 | ||
6 | - | local warning = 20 -- Warning level in % |
6 | + | local max = 99 -- Warning level in % |
7 | local min = 10 -- Warning level in % | |
8 | local cap -- Tank capacity | |
9 | local amount -- Amount liquid in tank | |
10 | local percentfull -- Percent liquid in tank | |
11 | local lastpercent = 1000 -- Percent last loop | |
12 | local sendmsg -- Message to send | |
13 | local sleeptime -- How long to sleep | |
14 | local sendFreq = 3 -- Modem Frequency | |
15 | local content = "Water" -- What is in tank? | |
16 | -- Make sure frequency match the main computer | |
17 | - | -- Set warning lamp to off |
17 | + | |
18 | - | redstone.setOutput("right", false) |
18 | + | |
19 | while true do | |
20 | -- Fill table with data from tank valve | |
21 | tanksTable = val.getTankInfo("WhatIsThis") | |
22 | maintank = tanksTable[1] | |
23 | - | mon.clear() |
23 | + | |
24 | - | mon.setCursorPos(1,1) |
24 | + | |
25 | cap = maintank.capacity / 1000 -- in buckets | |
26 | amount = maintank.amount -- in millibuckets | |
27 | - | tanksTable = val.getTanks("WhatIsThis") |
27 | + | |
28 | -- If tank is empty, to avoid math issues with 0 | |
29 | if amount == nil then | |
30 | amount = 0 | |
31 | percentfull = 0 | |
32 | else | |
33 | -- Use math.floor to convert to integers | |
34 | amount = math.floor(amount / 1000) | |
35 | percentfull = math.floor(100 * amount / cap) | |
36 | end | |
37 | ||
38 | -- Check for change since last loop | |
39 | if percentfull == lastpercent then | |
40 | sleep(1) | |
41 | else | |
42 | -- If value changed, send to main! | |
43 | sendmsg = content ..": " ..percentfull .." %" | |
44 | - | -- Self explanatory :) |
44 | + | |
45 | - | mon.write(content) |
45 | + | |
46 | - | mon.setCursorPos(1,2) |
46 | + | |
47 | - | mon.write("Amount: " ..amount .."/"..cap .." B.") |
47 | + | |
48 | - | mon.setCursorPos(1,3) |
48 | + | |
49 | - | mon.write("Amount: " ..percentfull .."% ") |
49 | + | |
50 | if percentfull < min then | |
51 | redstone.setOutput("right", true) | |
52 | end | |
53 | - | print("Still " ..percentfull .. "%, nothing sent.") |
53 | + | |
54 | if percentfull > max then | |
55 | redstone.setOutput("right", false) | |
56 | end | |
57 | ||
58 | - | print("Sent: " ..sendmsg) |
58 | + | sleep(10) |
59 | end |