littlewire 0.9.3 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -163,8 +163,9 @@ class LittleWire
163
163
  def ws2811 pin = false
164
164
  raise "You need to update your LittleWire firmware to version 1.2 to use One Wire" unless version_hex >= 0x12
165
165
  @ws2811 ||= Array.new
166
- @ws2811[pin || 0] ||= WS2811.new(self, pin)
167
- return @ws2811[pin || 0]
166
+ pin = get_pin(LittleWire::DigitalPinMap, pin || 0)
167
+ @ws2811[pin] ||= WS2811.new(self, pin)
168
+ return @ws2811[pin]
168
169
  end
169
170
 
170
171
  alias_method :ws2812, :ws2811
@@ -39,10 +39,11 @@ class LittleWire::WS2811
39
39
  end
40
40
  end
41
41
 
42
- def set *colors
42
+ def send *colors
43
43
  @colors = colors.flatten
44
44
  output
45
45
  end
46
+ alias_method :set, :send
46
47
 
47
48
  def black!
48
49
  @colors = ['black'] * 64
@@ -55,8 +56,8 @@ class LittleWire::WS2811
55
56
  def preload color
56
57
  @wire.control_transfer(
57
58
  function: :ws2812,
58
- wIndex: color.b << 8 | color.r,
59
- wValue: color.g << 8 | 0x20
59
+ wIndex: color.b.to_i << 8 | color.r.to_i,
60
+ wValue: color.g.to_i << 8 | 0x20
60
61
  )
61
62
  end
62
63
 
@@ -64,7 +65,7 @@ class LittleWire::WS2811
64
65
  def flush pin
65
66
  @wire.control_transfer(
66
67
  function: :ws2812,
67
- wIndex: 0, wValue: pin | 0x10
68
+ wIndex: 0, wValue: pin.to_i | 0x10
68
69
  )
69
70
  output_delay(@colors.length)
70
71
  end
@@ -77,8 +78,8 @@ class LittleWire::WS2811
77
78
  def write color, pin
78
79
  @wire.control_transfer(
79
80
  function: :ws2812,
80
- wIndex: color.b << 8 | color.r,
81
- wValue: color.g << 8 | pin | 0x30
81
+ wIndex: color.b.to_i << 8 | color.r.to_i,
82
+ wValue: color.g.to_i << 8 | pin.to_i | 0x30
82
83
  )
83
84
  output_delay(@colors.length)
84
85
  end
@@ -86,8 +87,8 @@ class LittleWire::WS2811
86
87
  # wait as long as it will take for the message to output to the LED strip, so we don't make
87
88
  # any more USB requests while the device is busy flushing pixels with interrupts disabled
88
89
  def output_delay(pixels)
89
- # each pixel consumes 30us for it's data, plus 50us reset at end of transmission
90
- sleep((0.00003 * pixels) + 0.00005)
90
+ # each pixel consumes 30us for it's data, plus a little extra for reset
91
+ sleep((0.00003 * pixels) + 0.001)
91
92
  end
92
93
  end
93
94
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: littlewire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
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-05-27 00:00:00.000000000 Z
12
+ date: 2013-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: libusb
@@ -68,11 +68,6 @@ files:
68
68
  - examples/blinky.rb
69
69
  - examples/fadey.rb
70
70
  - examples/led pixel.rb
71
- - examples/ws2811 audio.rb
72
- - examples/ws2811 colors.rb
73
- - examples/ws2811 scan.rb
74
- - examples/ws2811 strobe.rb
75
- - examples/ws2811.rb
76
71
  homepage: http://creativepony.com/littlewire/
77
72
  licenses: []
78
73
  post_install_message:
@@ -1,7 +0,0 @@
1
- begin
2
- require 'ffi-portaudio'
3
- rescue
4
- puts "Need to install ffi-portaudio rubygem to use this example"
5
- end
6
- require 'littlewire'
7
-
@@ -1,20 +0,0 @@
1
- require 'littlewire'
2
- wire = LittleWire.connect
3
- pin = :pin1
4
- speed = 1
5
- num_leds = 64
6
-
7
- loop do
8
- puts "red"
9
- wire.ws2811.colors = ['red'] * num_leds
10
- wire.ws2811.output pin
11
- sleep speed
12
- puts "green"
13
- wire.ws2811.colors = ['green'] * num_leds
14
- wire.ws2811.output pin
15
- sleep speed
16
- puts "blue"
17
- wire.ws2811.colors = ['blue'] * num_leds
18
- wire.ws2811.output pin
19
- sleep speed
20
- end
@@ -1,25 +0,0 @@
1
- require 'littlewire'
2
- wire = LittleWire.connect
3
- num_pixels = ARGV.first.to_i
4
-
5
- lit = 0
6
- loop do
7
-
8
- text_output = ['-'] * num_pixels
9
- text_output[lit] = '*'
10
- puts text_output.join
11
-
12
- wire.ws2811.colors = num_pixels.times.map do |idx|
13
- if idx == lit
14
- 'white'.to_color
15
- else
16
- 'black'.to_color
17
- end
18
- end
19
- wire.ws2811.output :pin1
20
-
21
- lit += 1
22
- lit %= num_pixels
23
-
24
- sleep 0.02
25
- end
@@ -1,29 +0,0 @@
1
- require 'littlewire'
2
- wire = LittleWire.connect
3
- pin = :pin1
4
- num_leds = 10
5
- MaxBPM = 500
6
-
7
- strobe_duration = 0.01
8
- bpm = 30
9
-
10
- Thread.start do
11
- loop do
12
- print "Enter BPM: "
13
- new_bpm = (gets.to_f rescue bpm)
14
- new_bpm = MaxBPM if new_bpm > MaxBPM
15
- bpm = new_bpm
16
- puts "Set to #{bpm}"
17
- end
18
- end
19
-
20
- loop do
21
- wire.ws2811.colors = ['white'] * num_leds
22
- wire.ws2811.output pin
23
- sleep(strobe_duration)
24
-
25
- wire.ws2811.colors = ['black'] * num_leds
26
- wire.ws2811.output pin
27
- blackout_duration = (60.0 / bpm) - strobe_duration
28
- sleep((60.0 / bpm) - strobe_duration) if blackout_duration > 0
29
- end
@@ -1,39 +0,0 @@
1
- # Send up to 64 colours to a string of WS2812 LEDs or 800khz (version 2) Adafruit Flora NeoPixels
2
- # Any 800khz mode ws2811 pixels will work
3
- require 'littlewire'
4
- wire = LittleWire.connect
5
-
6
- puts DATA.read # print out the little ascii art thing at the end of this file
7
- puts "Which pin to use for data output?"
8
- print "Enter pin number: "
9
- output_pin = gets.gsub(/[^0-9]/, '').to_i
10
-
11
- print "Enter 1st color: "
12
- wire.ws2811.colors = [gets.strip.to_color]
13
- wire.ws2811.output(output_pin) # output our first color
14
-
15
- titles = ['1st', '2nd', '3rd']
16
-
17
- 63.times do |idx|
18
- print "Enter #{titles[idx + 1] || "#{idx + 2}th"} color: "
19
- gotten = gets.strip
20
- break if gotten.empty?
21
- # add colour to array
22
- wire.ws2811.colors.push gotten.to_color
23
- wire.ws2811.output(output_pin) # output the colours to the string
24
- end
25
-
26
- puts "All done!"
27
-
28
- __END__
29
- LittleWire connector: | Digispark Board:
30
- /-----\ | _________
31
- pin_1 | o o | vcc | _____| o| ds5
32
- pin_2 | o o | pin 4 | |----- o| (usb - not available)
33
- pin_3 | o o | gnd | |----- o| (usb - not available)
34
- \-----/ | |----- o| ds2
35
- |----- o| ds1
36
- |_o_o_o__o| ds0
37
- 5 g v
38
- v n c
39
- d c