tlc59116 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tlc59116.rb +55 -1
- data/lib/tlc59116/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 656ea0310e6c77e531fd18afdc0af21e40c559ac
|
4
|
+
data.tar.gz: 566b6e483117c5ab6622a1881f042e9fdfe66623
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75e285ad24d797ebceeb823b51203646183a27e1ce264aaec76bc968f681720eadd254b49677f5246bc94140a1abb1dfec2b08807fc4ed703bf9742d401bb0e7
|
7
|
+
data.tar.gz: 318cce64b633c741606401182112f94b72f7b244399519a07bc93483c0960bee3f53d089dab43e194505fb908ad29391b7b43e8db0116c660985c456d2eff6af
|
data/lib/tlc59116.rb
CHANGED
@@ -5,9 +5,63 @@ module Tlc59116
|
|
5
5
|
class Tlc59116
|
6
6
|
I2C_ADDRESS = 0x1B
|
7
7
|
|
8
|
+
module Register
|
9
|
+
MODE1 = 0x00,
|
10
|
+
MODE2 = 0x01,
|
11
|
+
PWM = 0x02,
|
12
|
+
LED_OUT_0 = 0x14,
|
13
|
+
ERROR_FLAGS1 = 0x1D,
|
14
|
+
ERROR_FLAGS2 = 0x1E
|
15
|
+
end
|
16
|
+
|
17
|
+
AUTO_INCREMENT = 0x80;
|
18
|
+
|
8
19
|
def initialize port
|
9
20
|
@i2c = I2C.create port
|
10
21
|
end
|
11
|
-
|
22
|
+
|
23
|
+
def enable
|
24
|
+
write Register::MODE1, 0x00;
|
25
|
+
end
|
26
|
+
|
27
|
+
def disable
|
28
|
+
write Register::MODE1, 0x10;
|
29
|
+
end
|
30
|
+
|
31
|
+
def pwm_control value
|
32
|
+
write Register::LED_OUT_0 | AUTO_INCREMENT, *value
|
33
|
+
end
|
34
|
+
|
35
|
+
def pwm address, value
|
36
|
+
write Register::PWM | AUTO_INCREMENT, *value
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def read register, read_bytes = 1
|
41
|
+
@i2c.read I2C_ADDRESS , read_bytes , register
|
42
|
+
end
|
43
|
+
|
44
|
+
def read_byte register
|
45
|
+
data = read register
|
46
|
+
data.unpack("C").first
|
47
|
+
end
|
48
|
+
|
49
|
+
def read_short register
|
50
|
+
data = read register, 2
|
51
|
+
data.unpack("S_").first
|
52
|
+
end
|
53
|
+
|
54
|
+
def write register, value
|
55
|
+
@i2c.write I2C_ADDRESS, *value
|
56
|
+
end
|
57
|
+
|
12
58
|
end
|
13
59
|
end
|
60
|
+
|
61
|
+
|
62
|
+
# sends every param, begining with +params[0]+
|
63
|
+
# If the current param is a Fixnum, it is treated as one byte.
|
64
|
+
# If the param is a String, this string will be send byte by byte.
|
65
|
+
# You can use Array#pack to create a string from an array
|
66
|
+
# For Fixnum there is a convinient function to_short which transforms
|
67
|
+
# the number to a string this way: 12345.to_short == [12345].pack("s")
|
data/lib/tlc59116/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tlc59116
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sille Van Landschoot
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|