Skip to content
Browse files

added lua example

  • Loading branch information...
derekmolloy committed May 13, 2018
1 parent 8e54a61 commit 34845315929ccec1556d78a21f82266426f2b612
Showing with 37 additions and 0 deletions.
  1. +37 −0 chp05/luaLED/luaLED.lua
@@ -0,0 +1,37 @@
local LED3_PATH = "/sys/class/leds/beaglebone:green:usr3/"

-- Example function to write a value to the GPIO
function writeLED(directory, filename, value)
file =, "w") -- append dir and file names
file:write(value) -- write the value to the file

print("Starting the Lua LED Program")
if arg[1]==nil then -- no argument provided?
print("This program requires a command")
print(" usage is: ./luaLED.lua command")
print("where command is one of on, off, or status")
do return end
if arg[1]=="on" then
print("Turning the LED on")
writeLED(LED3_PATH, "trigger", "none")
os.execute("sleep 0.1")
writeLED(LED3_PATH, "brightness", "1")
elseif arg[1]=="off" then
print("Turning the LED off")
writeLED(LED3_PATH, "trigger", "none")
os.execute("sleep 0.1")
writeLED(LED3_PATH, "brightness", "0")
elseif arg[1]=="status" then
print("Getting the LED status")
file ="brightness", "r")
print(string.format("The LED state is %s.", file:read()))
print("Invalid command!")
print("End of the Lua LED Program")

0 comments on commit 3484531

Please sign in to comment.
You can’t perform that action at this time.