-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpiod_example.lua
More file actions
45 lines (37 loc) · 1.12 KB
/
gpiod_example.lua
File metadata and controls
45 lines (37 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env lua
--[[
Complete gpiod Lua wrapper library usage example
Demonstrates how to use the generic gpiod library for GPIO operations
]]
-- Add current directory to package path
local gpiod = require("gpiod")
print("=== gpiod Lua Wrapper Library Example ===")
print("gpiod version:", gpiod.version())
-- Open GPIO chip
local chip = gpiod.chip_open("gpiochip4")
print("Chip name:", chip:name())
print("Chip label:", chip:label())
print("Number of GPIO lines:", chip:num_lines())
-- Get GPIO line (e.g., GPIO 18)
local line = chip:get_line(18)
print("GPIO line offset:", line:offset())
print("GPIO line name:", line:name() or "No name")
print("Is line used:", line:is_used())
-- Request output mode
line:request_output("example", 0)
print("GPIO direction:", line:direction())
print("Consumer:", line:consumer())
-- LED blinking example
print("Starting GPIO 18 blinking (5 times)...")
for i = 1, 5 do
print("Setting high level")
line:set_value(1)
gpiod.sleep(0.5)
print("Setting low level")
line:set_value(0)
gpiod.sleep(0.5)
end
-- Clean up resources
line:release()
chip:close()
print("Example completed")