Skip to content

Commit

Permalink
Update APA102 examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vickash committed Oct 6, 2024
1 parent 6a19805 commit adb1e94
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
7 changes: 3 additions & 4 deletions examples/led/apa102_bounce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
# 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)

# Use the default hardware SPI bus.
bus = Denko::SPI::Bus.new(board: board)
board = Denko::Board.new(Denko::Connection::Serial.new)
bus = Denko::SPI::Bus.new(board: board)
strip = Denko::LED::APA102.new(bus: bus, length: PIXELS)

loop do
Expand All @@ -27,7 +26,7 @@
strip.clear
strip[index] = color
strip.show
sleep 0.05
sleep 0.025
end
end
end
34 changes: 17 additions & 17 deletions examples/led/apa102_fade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,36 @@
BLUE = [0, 0, 255]
WHITE = [255, 255, 255]
COLORS = [RED, GREEN, BLUE, WHITE]
PIXELS = 3
PIXELS = 4

# Get all the brightness values as an array.
brightness_steps = (0..31).to_a

board = Denko::Board.new(Denko::Connection::Serial.new)
brightness_steps = (0..31).to_a + (1..30).to_a.reverse

# Use the default hardware SPI bus.
bus = Denko::SPI::Bus.new(board: board)
board = Denko::Board.new(Denko::Connection::Serial.new)
bus = Denko::SPI::Bus.new(board: board)
strip = Denko::LED::APA102.new(bus: bus, length: PIXELS)

# Test global brightness control first.
strip[0] = RED
strip[1] = GREEN
strip[2] = BLUE
strip[3] = WHITE

# Fade up from 0 brightness then back down.
(brightness_steps + brightness_steps.reverse).each do |value|
# Fade all 4 in sync using global brightness control.
brightness_steps.each do |value|
strip.brightness = value
strip.show
sleep 0.05
end

# Test per-pixel brightness by fading different pixels different directions.
loop do
(brightness_steps + brightness_steps.reverse).each do |value|
strip[0] = RED + [value]
strip[1] = GREEN + [31 - value]
strip[2] = BLUE + [value]
strip.show
sleep 0.1
end
# Set 4th pixel back to full brightness white.
strip[3] = WHITE + [31]

# Fade per-pixel, in different directions.
brightness_steps.cycle do |value|
strip[0] = RED + [value]
strip[1] = GREEN + [31 - value]
strip[2] = BLUE + [value]
strip.show
sleep 0.025
end

0 comments on commit adb1e94

Please sign in to comment.