BBB 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
- - 2.0.0
5
- - ruby-head
4
+ - 2.1.0
6
5
  - jruby-head
@@ -0,0 +1,34 @@
1
+ require 'BBB'
2
+
3
+ class Circuit < BBB::Circuit
4
+ include BBB::Components
5
+
6
+ def initialize
7
+ attach Servo, pins: :P8_13, as: :servo
8
+ attach AnalogComponent, pin: :P9_40, as: :ldr
9
+ end
10
+ end
11
+
12
+ class LDRServo < BBB::Application
13
+ attr_accessor :min, :max
14
+
15
+ circuit Circuit.new
16
+
17
+ def initialize(min, max)
18
+ @min = min
19
+ @max = max
20
+ end
21
+
22
+ def run
23
+ servo.angle(angle)
24
+ end
25
+
26
+ def range
27
+ max - min
28
+ end
29
+
30
+ def angle
31
+ (ldr.value - min) / range.to_f * 180
32
+ end
33
+
34
+ end
@@ -48,6 +48,7 @@ module BBB
48
48
  # @return Array[Pins]
49
49
  #
50
50
  def initialize_pins(*positions)
51
+ positions.flatten!
51
52
  opts = positions.last.kind_of?(Hash) ? positions.pop : {}
52
53
 
53
54
  verify_pin_position_count(positions)
@@ -14,12 +14,15 @@ module BBB
14
14
  def after_pin_initialization
15
15
  pin.period = 17e6
16
16
  pin.duty = (min_duty + duty_range / 2)
17
- pin.run = 0
17
+ pin.run = 1
18
18
  end
19
19
 
20
20
  def angle(degrees)
21
- value = degrees / 180.to_f * duty_range + min_duty
22
- pin.duty = value
21
+ pin.duty = degrees_to_ns(degrees)
22
+ end
23
+
24
+ def degrees_to_ns(degrees)
25
+ degrees / 180.to_f * duty_range + min_duty
23
26
  end
24
27
 
25
28
  def activate!
data/lib/BBB/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module BBB
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: BBB
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-29 00:00:00.000000000 Z
12
+ date: 2013-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -91,6 +91,7 @@ files:
91
91
  - examples/analog_pin.rb
92
92
  - examples/led.rb
93
93
  - examples/light_switch.rb
94
+ - examples/servo_ldr.rb
94
95
  - examples/sketches.rb
95
96
  - lib/BBB.rb
96
97
  - lib/BBB/application.rb
@@ -142,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
143
  version: '0'
143
144
  segments:
144
145
  - 0
145
- hash: -4049511338370384928
146
+ hash: -4269646228377431993
146
147
  required_rubygems_version: !ruby/object:Gem::Requirement
147
148
  none: false
148
149
  requirements:
@@ -151,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
152
  version: '0'
152
153
  segments:
153
154
  - 0
154
- hash: -4049511338370384928
155
+ hash: -4269646228377431993
155
156
  requirements: []
156
157
  rubyforge_project:
157
158
  rubygems_version: 1.8.25