arduino-lights 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/arduino-lights.rb +58 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c0b8469046ecfb3cca87bace15e330bfa9018135
|
4
|
+
data.tar.gz: fa69757d67d1fe221aeaa2d854d86adcbc102a23
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '0492f9046cb9bdf9a2b420f1c4185a6fb067a63e5cacf63fcc2326a393550a8785eb9437b4be2532753366275fe1988f7e651f0b49d864de8b8c288dc66af742'
|
7
|
+
data.tar.gz: 979b8ad7fe171c295589bf8cda548dc7c1a639d263483c2670f7e5c6545935d976bd6c40e5822dbe57a0723b1e8ac2255ecb7104f9ec9cb0b708011dd3f05c2c
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'serialport'
|
2
|
+
|
3
|
+
module ArduinoLights
|
4
|
+
SERIAL_PORT = "/dev/ttyUSB0"
|
5
|
+
SERIAL_RATE = 115200
|
6
|
+
PIXELS = 24
|
7
|
+
|
8
|
+
def self.serial_port
|
9
|
+
@port ||= begin
|
10
|
+
res = SerialPort.new(SERIAL_PORT, baud: SERIAL_RATE, flow_control: SerialPort::SOFT)
|
11
|
+
sleep(2)
|
12
|
+
res
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.set_pixel(pixel, red, green, blue)
|
17
|
+
# Something about the setup with these LEDs requires a small delay between bytes sent
|
18
|
+
# I don't know if this is about the configuration of ruby-serialport, or the pixel
|
19
|
+
# processing code on the Arduino itself.
|
20
|
+
#
|
21
|
+
# With this set to 0.0009, data runs through the device at about 5kb/s. With this set
|
22
|
+
# to 0.0008, the data runs through at >5.5kb/s, which causes some of the data to be lost
|
23
|
+
sleep(0.0009)
|
24
|
+
|
25
|
+
# first byte is whice led number to switch on
|
26
|
+
self.serial_port.write(pixel.chr)
|
27
|
+
|
28
|
+
# next 3 bytes are red, green and blue values
|
29
|
+
# Note: 255 signifies the end of the command, so don't try and set an led value to that
|
30
|
+
self.serial_port.write(red.chr)
|
31
|
+
self.serial_port.write(green.chr)
|
32
|
+
self.serial_port.write(blue.chr)
|
33
|
+
|
34
|
+
# then end with a termination character
|
35
|
+
self.serial_port.write(255.chr)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.radial_pixel_index(value, range)
|
39
|
+
(((PIXELS.to_f * value) / range).floor + PIXELS) % PIXELS
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.draw_pixel_map(pixels)
|
43
|
+
pixels.each_with_index do |pixel,i|
|
44
|
+
set_pixel(PIXELS - i - 1, pixel[0], pixel[1], pixel[2])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
if __FILE__ == $0
|
51
|
+
pixel = 0
|
52
|
+
while (true)
|
53
|
+
pixels = (0..(Arduino::PIXELS-1)).map { [0,0,0] }
|
54
|
+
pixels[pixel] = [100,50,50]
|
55
|
+
Arduino::draw_pixel_map(pixels)
|
56
|
+
pixel = (pixel + 1) % Arduino::PIXELS
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arduino-lights
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arthur Taylor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: serialport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.1
|
27
|
+
description: Simple gem to wrap the serial port control for ruby projects controlling
|
28
|
+
an Arduino with LEDs attached
|
29
|
+
email: arthur.taylor@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/arduino-lights.rb
|
35
|
+
homepage: http://github.com/codders/arduino-lights
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 2.6.11
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: LED control for ruby via arduino
|
59
|
+
test_files: []
|