littlewire 0.9.2 → 0.9.3
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.
- data/examples/blinky.rb +1 -1
- data/examples/fadey.rb +1 -1
- data/examples/led pixel.rb +1 -1
- data/examples/ws2811 audio.rb +7 -0
- data/examples/ws2811 colors.rb +1 -1
- data/examples/ws2811 scan.rb +2 -2
- data/examples/ws2811 strobe.rb +29 -0
- data/examples/ws2811.rb +1 -1
- data/lib/littlewire.rb +1 -2
- data/lib/ws2811.rb +53 -12
- metadata +3 -1
data/examples/blinky.rb
CHANGED
@@ -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 '
|
4
|
+
require 'littlewire.rb'
|
5
5
|
|
6
6
|
wire = LittleWire.connect
|
7
7
|
|
data/examples/fadey.rb
CHANGED
@@ -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 '
|
4
|
+
require 'littlewire.rb'
|
5
5
|
|
6
6
|
wire = LittleWire.connect
|
7
7
|
|
data/examples/led pixel.rb
CHANGED
data/examples/ws2811 colors.rb
CHANGED
data/examples/ws2811 scan.rb
CHANGED
@@ -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
|
data/examples/ws2811.rb
CHANGED
@@ -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 '
|
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
|
data/lib/littlewire.rb
CHANGED
@@ -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
|
-
:
|
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 ###
|
data/lib/ws2811.rb
CHANGED
@@ -30,23 +30,64 @@ class LittleWire::WS2811
|
|
30
30
|
until colors_buffer.empty?
|
31
31
|
|
32
32
|
if colors_buffer.length > 1
|
33
|
-
|
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
|
-
|
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.
|
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: []
|