-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcd.rb
More file actions
63 lines (49 loc) · 1003 Bytes
/
lcd.rb
File metadata and controls
63 lines (49 loc) · 1003 Bytes
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env ruby
require 'rubygems'
require 'i2c'
class Lcd
def initialize(path, address = 0x3e)
@device = I2C.create(path)
@address = address
write(0, "\x38\x39\x14\x78\x5e\x6c")
sleep 0.25
write(0, "\x0c\x01\x06")
sleep 0.05
clear
end
def write(addr, data)
@device.write(@address, addr, data)
end
def clear
write(0, "\x01")
end
def move(x,y)
write(0, 128 + 64 * y + x)
end
def disp(text)
write(0x40, text)
end
end
sensor = Lcd.new('/dev/i2c-1')
sensor.move 0,0
sensor.disp(`hostname`.chop)
sensor.move 0,1
sensor.disp(`hostname -I`.chop)
GPIO = 4
exp = open("/sys/class/gpio/export", "w")
exp.write(GPIO)
exp.close
dir = open("/sys/class/gpio/gpio#{GPIO}/direction", "w")
dir.write("out")
dir.close
out = 1
20.times do
val = open("/sys/class/gpio/gpio#{GPIO}/value", "w")
val.write(out)
val.close
out = out == 1 ? 0 : 1
sleep 0.5
end
uexp = open("/sys/class/gpio/unexport", "w")
uexp.write(GPIO)
uexp.close