Skip to content

Commit

Permalink
add another output, need testing
Browse files Browse the repository at this point in the history
  • Loading branch information
be-ska committed Dec 8, 2024
1 parent 18a0618 commit e76770a
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions GA45_bucket.lua
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
-- control bucket position with RC input - version 1.0

-- user parameters
local RELAY_PIN_UP = 55 -- APx ch 6
local RELAY_PIN_DOWN = 60 -- APx ch 11 (RPM)
local MILLIS_UPDATE = 100
local RELAY_PIN_UP = 1
local RELAY_PIN_DOWN = 2
local RELAY_PIN_B_UP = 3
local RELAY_PIN_B_DOWN = 4
local MILLIS_UPDATE = 150

-- parameters
local PARAM_TABLE_KEY = 42
assert(param:add_table(PARAM_TABLE_KEY, "BUCK_", 1), "could not add param table")
assert(param:add_table(PARAM_TABLE_KEY, "BUCK_", 2), "could not add param table")
assert(param:add_param(PARAM_TABLE_KEY, 1, "CH", 2), "could not add param 1")
assert(param:add_param(PARAM_TABLE_KEY, 2, "CH_B", 3), "could not add param 2")

-- bind parameters to variables
local BUCK_CH = Parameter()
local BUCK_CH = Parameter("BUCK_CH")
local BUCK_CH_B = Parameter("BUCK_CH_B")
BUCK_CH:init("BUCK_CH")

function init()
-- set relay mode
gpio:pinMode(RELAY_PIN_UP,1) -- set RELAY pin as output
gpio:pinMode(RELAY_PIN_DOWN,1) -- set RELAY pin as output
gpio:pinMode(RELAY_PIN_B_UP,1) -- set RELAY pin as output
gpio:pinMode(RELAY_PIN_B_DOWN,1) -- set RELAY pin as output
return update, 100
end

Expand All @@ -26,8 +32,11 @@ function update()
return update, 1000
elseif BUCK_CH:get() < 1 or BUCK_CH:get() > 12 then
return update, 1000
elseif BUCK_CH_B:get() < 1 or BUCK_CH_B:get() > 12 then
return update, 1000
else
local channel = math.floor(BUCK_CH:get())
local channel_b = math.floor(BUCK_CH_B:get())
local pwm = rc:get_pwm(channel)
if pwm > 900 and pwm < 1400 then
gpio:write(RELAY_PIN_UP, 0)
Expand All @@ -39,10 +48,20 @@ function update()
gpio:write(RELAY_PIN_UP, 0)
gpio:write(RELAY_PIN_DOWN, 0)
end
if pwm > 900 and pwm < 1400 then
gpio:write(RELAY_PIN_B_UP, 0)
gpio:write(RELAY_PIN_B_DOWN, 1)
elseif pwm > 1600 and pwm < 2100 then
gpio:write(RELAY_PIN_B_UP, 1)
gpio:write(RELAY_PIN_B_DOWN, 0)
else
gpio:write(RELAY_PIN_B_UP, 0)
gpio:write(RELAY_PIN_B_DOWN, 0)
end

return update, MILLIS_UPDATE
end
end

gcs:send_text(6, "bucket controller is running")
return init, 100
return init, 100

0 comments on commit e76770a

Please sign in to comment.