tlc59116 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/tlc59116.rb +36 -19
- data/lib/tlc59116/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c3be9aa2000fe69646651f1c09f2713513a3cba
|
4
|
+
data.tar.gz: f8152c7da1fbca636294c18a2ec0671ce2121dea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91957d75ac1a0337b981dc0342d9dff1e9035bf27a7f5c6db576da33e860af5b82f203696a0d82440aa403ec7a1f45eb03d683019135103cb72c8de2f93515ce
|
7
|
+
data.tar.gz: a02cfccdcc9b57ec88d8949d339e17e8677fcfadcf0bcf2902f29ff7b3babd85b651e46295c5687928a67716129196ad604a338a1e5a3e6eed03e46bb3d25fb9
|
data/.gitignore
CHANGED
data/lib/tlc59116.rb
CHANGED
@@ -3,37 +3,54 @@ require "i2c"
|
|
3
3
|
|
4
4
|
module Tlc59116
|
5
5
|
class Tlc59116
|
6
|
-
I2C_ADDRESS =
|
7
|
-
|
8
|
-
module
|
9
|
-
MODE1 = 0x00
|
10
|
-
MODE2 = 0x01
|
11
|
-
PWM = 0x02
|
12
|
-
|
13
|
-
|
6
|
+
I2C_ADDRESS = 0x68
|
7
|
+
|
8
|
+
module Registers
|
9
|
+
MODE1 = 0x00
|
10
|
+
MODE2 = 0x01
|
11
|
+
PWM = 0x02
|
12
|
+
GROUPBRIGHTNESS = 0x12
|
13
|
+
LED_OUT_0 = 0x14
|
14
|
+
ERROR_FLAGS1 = 0x1D
|
14
15
|
ERROR_FLAGS2 = 0x1E
|
15
16
|
end
|
16
17
|
|
17
18
|
AUTO_INCREMENT = 0x80;
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def initialize i2c
|
21
|
+
@i2c = i2c
|
22
|
+
end
|
23
|
+
|
24
|
+
def mode1 value
|
25
|
+
write Registers::MODE1, value
|
26
|
+
end
|
27
|
+
|
28
|
+
def mode2 value
|
29
|
+
write Registers::MODE2, value
|
30
|
+
end
|
22
31
|
|
23
32
|
def enable
|
24
|
-
|
33
|
+
value = read_byte Registers::MODE1
|
34
|
+
write Registers::MODE1, value & 0xEF
|
35
|
+
sleep 0.001
|
25
36
|
end
|
26
37
|
|
27
38
|
def disable
|
28
|
-
|
39
|
+
value = read_byte Registers::MODE1
|
40
|
+
write Registers::MODE1, value | 0x10
|
41
|
+
end
|
42
|
+
|
43
|
+
def pwm_control *value
|
44
|
+
write Registers::LED_OUT_0 | AUTO_INCREMENT, *value
|
29
45
|
end
|
30
46
|
|
31
|
-
def
|
32
|
-
|
47
|
+
def pwm *value, offset: offset = 0
|
48
|
+
raise "Offset must be smaller than 16" if offset >= 16
|
49
|
+
write (Registers::PWM + offset) | AUTO_INCREMENT, *value
|
33
50
|
end
|
34
51
|
|
35
|
-
def
|
36
|
-
write
|
52
|
+
def group_brightness value
|
53
|
+
write Registers::GROUPBRIGHTNESS, value
|
37
54
|
end
|
38
55
|
|
39
56
|
private
|
@@ -51,8 +68,8 @@ module Tlc59116
|
|
51
68
|
data.unpack("S_").first
|
52
69
|
end
|
53
70
|
|
54
|
-
def write register,
|
55
|
-
@i2c.write I2C_ADDRESS, *
|
71
|
+
def write register, *values
|
72
|
+
@i2c.write I2C_ADDRESS, register, *values
|
56
73
|
end
|
57
74
|
|
58
75
|
end
|
data/lib/tlc59116/version.rb
CHANGED