Sha256: cac298a9b5049f2f36cc65da4c4f142ad95cd99b5b6e2ff54af60825bb0c6777

Contents?: true

Size: 726 Bytes

Versions: 7

Compression:

Stored size: 726 Bytes

Contents

#
# Walk a single pixel along the length of a WS2812 strip and back,
# changing color each time it returns to position 0.
#
require 'bundler/setup'
require 'denko'

RED    = [255, 0, 0]
GREEN  = [0, 255, 0]
BLUE   = [0, 0, 255]
WHITE  = [255, 255, 255]
COLORS = [RED, GREEN, BLUE, WHITE]

WS2812_PIN = 4
PIXELS = 8

# Move along the strip and back, one pixel at a time.
positions = (0..PIXELS-1).to_a + (1..PIXELS-2).to_a.reverse

board = Denko::Board.new(Denko::Connection::Serial.new)
strip = Denko::LED::WS2812.new(board: board, pin: WS2812_PIN, length: PIXELS)

loop do
  COLORS.each do |color|
    positions.each do |index|
      strip.clear
      strip[index] = color
      strip.show
      sleep 0.05
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
denko-0.13.6 examples/led/ws2812_bounce.rb
denko-0.13.5 examples/led/ws2812_bounce.rb
denko-0.13.4 examples/led/ws2812_bounce.rb
denko-0.13.3 examples/led/ws2812_bounce.rb
denko-0.13.2 examples/led/ws2812_bounce.rb
denko-0.13.1 examples/led/ws2812_bounce.rb
denko-0.13.0 examples/led/ws2812_bounce.rb