View difference between Paste ID: 3UAJ0QUq and qQc7R4ms
SHOW: | | - or go back to the newest paste.
1-
--SpeedControlv1 by Gazer29
1+
--Radio Control v1 by Gazer29
2-
--Uses Automation mod version: Alpha 7
2+
3
local component = require("component")
4
local term = require ("term")
5
local trainRemote = component.ir_remote_control
6-
local entity = component.entity_link.getAPI("immersiverailroading:locomotivediesel")
6+
7-
local thread = require("thread")
7+
local flag = false
8-
require("PIDController")
8+
9
function helpdisplay()
10
	print("Radio Control v1")
11-
local MODE = 0 -- 0 SET, 1 RAMP,
11+
12-
local sleep = 1 -- seconds
12+
	print("'Any number'    - Changes Throttle")
13-
local display = false
13+
14
end
15
16
----------- Main loop ------------	
17-
	print("Speed Control v1")
17+
18
trainRemote.setBrake(0)
19-
	print("'Any number'    - Changes set speed")
19+
20-
	print("'+' 		- Displays additional information")
20+
while RUNNING do
21-
	print("'-' 		- Hides additional information")
21+
    term.clear()
22-
	print("'ramp'		- Changes to ramp mode, requires further input")
22+
    helpdisplay()
23-
	print("'idle'		- Pauses train control")
23+
24
    user = io.read()
25
	if user == "stop" then	
26-
	
26+
27-
function GetTrainPos()
27+
28-
	positions = entity.getLocation() 
28+
		RUNNING = false
29-
	xpos = positions.getX()
29+
    	term.clear()
30-
	ypos = positions.getY()
30+
31-
	zpos = positions.getZ()
31+
	if user == "h" then	
32-
	print("X: ", xpos)
32+
		print("Horn")
33-
	print("Z: ", zpos)
33+
		trainRemote.horn()
34
		end
35
    if user == "b" then	
36-
function GetTrainSpeed()
36+
		print("Bell")
37-
	speed = entity.getCurrentSpeed()
37+
        if flag == false then
38-
	return speed
38+
			trainRemote.bell(1)
39
            flag = true
40
            else
41-
function setThrottle(x)
41+
            trainRemote.bell(0)
42-
	if 0 >= x then x = 0 end
42+
            flag = false
43-
	if 1 <= x then x = 1 end
43+
            end
44-
	entity.setThrottleLevel(x)
44+
45-
	if display then
45+
46-
		print("Throttle: ", x)
46+
        input = tonumber(user)
47
        if -1 <= input and input <= 1 then
48
			print("Setting Throttle: ", user)
49
        	trainRemote.setThrottle(input)
50-
function setBrake(x)
50+
            end
51-
	if 0 >= x then x = 0 end
51+
52-
	if 1 <= x then x = 1 end
52+
    os.sleep(0.5)
53-
	entity.setAirBrakeLevel(x)
53+
54-
	if display then
54+
55-
		print("Brake:   ", x)
55+
trainRemote.setThrottle(0)
56
trainRemote.setBrake(1)
57