littlewire 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  # A little blinky test to show how to make stuff happen with a littlewire in ruby!
2
2
  #
3
3
  # To get started, plug an LED in to the ISP cable between ground and Pin 4 (they're next to each other)
4
- require '../lib/littlewire.rb'
4
+ require 'littlewire.rb'
5
5
 
6
6
  wire = LittleWire.connect
7
7
 
@@ -1,7 +1,7 @@
1
1
  # A little blinky test to show how to make stuff happen with a littlewire in ruby!
2
2
  #
3
3
  # To get started, plug an LED in to the ISP cable between ground and Pin 4 (they're next to each other) via a resistor (resistor not optional)
4
- require '../lib/littlewire.rb'
4
+ require 'littlewire.rb'
5
5
 
6
6
  wire = LittleWire.connect
7
7
 
@@ -6,7 +6,7 @@
6
6
  #
7
7
  # Note if you're running more than five or so from a littlewire you should power them
8
8
  # with an external power supply instead of Little Wire's VCC pin
9
- require '../lib/littlewire'
9
+ require 'littlewire'
10
10
 
11
11
  wire = LittleWire.connect
12
12
  spi = wire.spi
@@ -0,0 +1,7 @@
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,4 +1,4 @@
1
- require '../lib/littlewire.rb'
1
+ require 'littlewire'
2
2
  wire = LittleWire.connect
3
3
  pin = :pin1
4
4
  speed = 1
@@ -1,4 +1,4 @@
1
- require '../lib/littlewire.rb'
1
+ require 'littlewire'
2
2
  wire = LittleWire.connect
3
3
  num_pixels = ARGV.first.to_i
4
4
 
@@ -21,5 +21,5 @@ loop do
21
21
  lit += 1
22
22
  lit %= num_pixels
23
23
 
24
- sleep 0.01
24
+ sleep 0.02
25
25
  end
@@ -0,0 +1,29 @@
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,6 +1,6 @@
1
1
  # Send up to 64 colours to a string of WS2812 LEDs or 800khz (version 2) Adafruit Flora NeoPixels
2
2
  # Any 800khz mode ws2811 pixels will work
3
- require '../lib/littlewire.rb'
3
+ require 'littlewire'
4
4
  wire = LittleWire.connect
5
5
 
6
6
  puts DATA.read # print out the little ascii art thing at the end of this file
@@ -272,8 +272,7 @@ class LittleWire
272
272
  :onewire_write_bit, # 51
273
273
  :pic_24f_programming, # 52 - experimental
274
274
  :pic_24f_sendsix, # 53 - experimental
275
- :ws2812_write, # 54 - experimental
276
- :ws2812_preload # 55 - experimental
275
+ :ws2812, # 54 - experimental
277
276
  # special cases
278
277
  # pic 24f send bytes - request = 0xD*
279
278
  # i2c send multiple messages - request = 0xE* ### experimental ###
@@ -30,23 +30,64 @@ class LittleWire::WS2811
30
30
  until colors_buffer.empty?
31
31
 
32
32
  if colors_buffer.length > 1
33
- color = colors_buffer.shift
33
+ preload(colors_buffer.shift)
34
34
 
35
- @wire.control_transfer(
36
- function: :ws2812_preload,
37
- wIndex: color.b << 8 | color.r,
38
- wValue: color.g << 8
39
- )
40
35
  elsif colors_buffer.length == 1
41
- color = colors_buffer.shift
36
+ write(colors_buffer.shift, output_pin)
42
37
 
43
- @wire.control_transfer(
44
- function: :ws2812_write,
45
- wIndex: color.b << 8 | color.r,
46
- wValue: color.g << 8 | output_pin
47
- )
48
38
  end
49
39
  end
50
40
  end
41
+
42
+ def set *colors
43
+ @colors = colors.flatten
44
+ output
45
+ end
46
+
47
+ def black!
48
+ @colors = ['black'] * 64
49
+ output
50
+ end
51
+
52
+ private
53
+
54
+ # push another set of rgb values to the buffer
55
+ def preload color
56
+ @wire.control_transfer(
57
+ function: :ws2812,
58
+ wIndex: color.b << 8 | color.r,
59
+ wValue: color.g << 8 | 0x20
60
+ )
61
+ end
62
+
63
+ # send buffer from littlewire to LEDs
64
+ def flush pin
65
+ @wire.control_transfer(
66
+ function: :ws2812,
67
+ wIndex: 0, wValue: pin | 0x10
68
+ )
69
+ output_delay(@colors.length)
70
+ end
71
+
72
+ # optimises preload followed by flush in to a single usb call
73
+ # def write color, pin
74
+ # preload color
75
+ # flush pin
76
+ # end
77
+ def write color, pin
78
+ @wire.control_transfer(
79
+ function: :ws2812,
80
+ wIndex: color.b << 8 | color.r,
81
+ wValue: color.g << 8 | pin | 0x30
82
+ )
83
+ output_delay(@colors.length)
84
+ end
85
+
86
+ # wait as long as it will take for the message to output to the LED strip, so we don't make
87
+ # any more USB requests while the device is busy flushing pixels with interrupts disabled
88
+ 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)
91
+ end
51
92
  end
52
93
 
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.2
4
+ version: 0.9.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -68,8 +68,10 @@ files:
68
68
  - examples/blinky.rb
69
69
  - examples/fadey.rb
70
70
  - examples/led pixel.rb
71
+ - examples/ws2811 audio.rb
71
72
  - examples/ws2811 colors.rb
72
73
  - examples/ws2811 scan.rb
74
+ - examples/ws2811 strobe.rb
73
75
  - examples/ws2811.rb
74
76
  homepage: http://creativepony.com/littlewire/
75
77
  licenses: []