time7segment 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd590ba61ac0ca84caf4bc17241df795dc29e4cb
4
- data.tar.gz: 5477ec0522ab0baf974a64bd00aab8b1f88aae14
3
+ metadata.gz: 61cbcfd1bbd9338f9239559bdbe85d5f6b88febe
4
+ data.tar.gz: 2c4a3b043d0ec4720c1a9bedd5fbea2f3a1a005b
5
5
  SHA512:
6
- metadata.gz: 1d0752e7120d9c78665d9956df046f37866a646bd5061def2041751f8f06cd53d111f51eb62cbdf72e496401d81eccfd599400443b6b72d16f8d05d36bcf12cf
7
- data.tar.gz: 7f1a83d50a89b654081b372d7ff59a1388c62f481c6a371aee4ef8e24149b4170f60147d97bfe46f8cf3e761aca9b7ede13e2d7d553da80b57ba1415a023f220
6
+ metadata.gz: a055f59f679beafc745ffd37c03106a9120ab4fc257a1be4872f742c8049c92fb0b05ef532dbc88aa9c99d3f0e295aa854a749eccbee21a5125aea655e1ec93a
7
+ data.tar.gz: 6148261d32f7b23f9cbbf31c672362ddb48d68e202ea36113d29e01ca971f31f1b1bb55060bc49a0345401fc45727d6b1f38ce307759d5411a30b7b2db81d1f7
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/time7segment.rb CHANGED
@@ -7,6 +7,14 @@ require 'rpi'
7
7
 
8
8
  # Quick pin reference
9
9
  # ===================
10
+
11
+ # digits:
12
+ #
13
+ # digit: 1 2 3 4
14
+ # 7 seg pin: 12 9 8 6
15
+ # GPIO pin: 22 27 17 24
16
+
17
+ # segments:
10
18
  #
11
19
  # index: 0 1 2 3 4 5 6 7
12
20
  # segment: a b c d e f g dp
@@ -19,15 +27,18 @@ require 'rpi'
19
27
 
20
28
  class Time7Segment
21
29
 
22
- # d1 d2 d3 d4 a b c d e f g dp
23
- def initialize(gpio_pins=%w(22 27 17 24 11 4 23 8 20 10 18 25),
24
- refresh: 0.0025)
30
+ # d1 d2 d3 d4 a b c d e f g dp
31
+ def initialize(gpio=%w(22 27 17 24 11 4 23 8 20 10 18 25), refresh: 0.0045)
25
32
 
26
- pins = RPi.new(gpio_pins).pins
27
- @digits, @segments = pins.take(4), pins.slice(4..-1)
28
- @refresh = refresh
33
+ pins = RPi.new(gpio).pins
34
+ @digits, @segments, @refresh = pins.take(4), pins.slice(4..-1), refresh
35
+
36
+ a = [0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B, 0x5F, 0x70, 0x7F, 0x7B]
37
+
38
+ @numerals = a.map do |x|
39
+ x.to_s(2).rjust(7,'0').chars.map {|x| x == '1' ? :off : :on }
40
+ end
29
41
 
30
-
31
42
  end
32
43
 
33
44
  def start
@@ -36,11 +47,8 @@ class Time7Segment
36
47
 
37
48
  Time.now.strftime("%H%M").chars.each.with_index do |x,i|
38
49
 
39
- display(x.to_i)
40
- @segments[7].method( i == 1 ? :off : :on).call
41
- @digits[i].on
42
- sleep @refresh
43
- @digits[i].off
50
+ display(x.to_i); @segments[7].method( i == 1 ? :off : :on).call
51
+ @digits[i].on; sleep @refresh; @digits[i].off
44
52
 
45
53
  end
46
54
 
@@ -50,11 +58,11 @@ class Time7Segment
50
58
 
51
59
  private
52
60
 
53
- def display(c)
61
+ # Displays the segments for an input number between 0-9
62
+ #
63
+ def display(n)
54
64
 
55
- lookup = [0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B, 0x5F, 0x70, 0x7F, 0x7B]
56
- a = lookup[c].to_s(2).rjust(7,'0').chars.map {|x| x == '1' ? :off : :on}
57
- a.each.with_index {|x,i| @segments[i].method(x).call}
65
+ @numerals[n].each.with_index {|x,i| @segments[i].method(x).call}
58
66
 
59
67
  end
60
68
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time7segment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  +hK+FacNWYYl7NLDoAQDnx8UxWfUl7WpWi7B/U09XsOHNwhaTJsZ6GeVkdVm1E//
32
32
  W1B8FmCNgggaYQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2016-02-26 00:00:00.000000000 Z
34
+ date: 2016-02-27 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rpi
metadata.gz.sig CHANGED
Binary file