2 posts
Posted 14 August 2012 - 06:16 AM
I am trying to create some flight control software for my mobile base made from frames. basically what i am trying to do is make a program the same as redpulse that will send to a specific color a specifid amount of times preferably without having to set the pulse duration manually.
Basically what i want is to type north 20 and have it send 20 2 second pulses with a 1 second delay between pulses to a color i designate to go "north" and then rewrite one for each color / direction (north, south, east, west, up, and down)
i tried editing a version of redpulse but i have never done any programming of any sort except some basic html and i cant seem to get anywhere.. if anyone could help point me in a direction to get started would much appreciate it.
992 posts
Posted 14 August 2012 - 07:51 AM
This program will do as requested
Spoiler
--[[
Base Mover
By Big SHiny Toys
14 AUG 2012
Notes:
white
orange
magenta
lightBlue
yellow
lime
pink
gray
lightGray
cyan
purple
blue
brown
green
red
black
]]--
local inError = false
local errorNO = 0
local sBundelSide = "back" -- change this
local nPulseTime = 2 -- ajustible
local tColor = {}
tColor.up = "white"
tColor.down = "orange"
tColor.north = "magenta"
tColor.east = "lightBlue"
tColor.south = "yellow"
tColor.west = "lime"
function sleepBreak( _nTime )
local timer = os.startTimer( _nTime )
while true do
local sEvent, param = os.pullEvent()
if sEvent == "timer" and param == timer then
return true
elseif sEvent == "key" and param == 14 then
return false
end
end
end
local function inputError()
if errorNO == 1 then
print("Please Enter a direction and a distance in meters")
print("Example: North 20")
elseif errorNO == 2 then
print("User Halted Move")
end
end
while true do
rs.setBundledOutput(sBundelSide,0)
term.clear()
term.setCursorPos(1,1)
print("Welcom to Base Driver")
print("selections are:")
print("Up Down North East South West or Exit")
if inError then
inputError()
inError = false
errorNO = 0
end
write("Move ")
sLine = read()
local tWords = {}
for match in string.gmatch(sLine, "[^ t]+") do
table.insert( tWords, match )
end
if #tWords == 1 then
if string.lower(tWords[1]) == "exit" then
break
else
tWords[2] = 1
end
end
if #tWords == 2 and tonumber(tWords[2]) ~= nil then
tWords[1] = string.lower(tWords[1])
if tWords[1] == "up" or tWords[1] == "down" or tWords[1] == "north" or tWords[1] == "east" or tWords[1] == "south" or tWords[1] == "west" then
print("Moving "..tWords[1].." "..tWords[2])
local nBundleVal = colors[tColor[tWords[1]]]
for i = 1,tWords[2] do
if not sleepBreak(nPulseTime) then
inError = true
errorNO = 2
break
end
rs.setBundledOutput(sBundelSide,nBundleVal)
if not sleepBreak(nPulseTime) then
inError = true
errorNO = 2
break
end
rs.setBundledOutput(sBundelSide,0)
end
else
inError = true
errorNO = 1
end
else
inError = true
errorNO = 1
end
end
term.clear()
term.setCursorPos(1,1)
print("Thank you for using Base Driver")
if you input wrong move and want to cancel it Quickly press Backspace
2 posts
Posted 14 August 2012 - 09:12 AM
works beautifully! very much appreciated and very nicely done.. thank you so much!