SwiftLED is a high-level library to control addressable LEDs (e.g. WS2812/NeoPixel) with animations and effects. It's designed to run on a Raspberry Pi.
There is a companion app for MacOS called SwiftLEDSimulator that allows you to test out your LED programs before sending your code to the embedded device (e.g. Raspberry Pi). The animations below are screenshots from this app.
ledStrip.leds[5].fill(.orange)
ledStrip.fill(Color(red: 0, green: 100, blue: 155))
let leds = stride(from: 0, to: ledStrip.leds.count, by: 5).map { ledStrip.leds[$0] }
leds.fill(.green)
ledStrip.fill(Gradient(.red, .orange, .yellow, .orange, .red))
ledStrip.repeatForever {
ledStrip.animate(.red, start: 0..<1, end: 45..<46, duration: 2.0)
ledStrip.animate(.green, start: 0..<1, end: 45..<46, duration: 2.0)
ledStrip.animate(.blue, start: 0..<1, end: 45..<46, duration: 2.0)
}
ledStrip.repeatForever {
ledStrip.animate(.red, start: 45..<47, end: 0..<2, duration: 2.0)
ledStrip.animate(.green, start: 0..<2, end: 45..<47, duration: 2.0)
ledStrip.animate(.blue, start: 45..<47, end: 0..<2, duration: 2.0)
}
ledStrip.sequence {
ledStrip.animate(.red, start: 0..<1, end: 0..<45, duration: 1.0)
ledStrip.animate(.green, start: 0..<1, end: 0..<45, duration: 1.0)
ledStrip.animate(.blue, start: 0..<1, end: 0..<45, duration: 1.0)
}
ledStrip.repeat(3) {
ledStrip.animate(Gradient(.black, .white), start: 0..<6, end: 45..<51, duration: 2)
}
let rainbow = Gradient(.red, .green, .blue, .red)
ledStrip.repeat(2) {
ledStrip.animate(rainbow, start: 0..<1, end: 0..<180, duration: 2.0, fillSize: 180)
}
let rainbow = Gradient(.red, .green, .blue, .red)
ledStrip.repeat(2) {
ledStrip.animate(rainbow, start: 0..<45, end: 45..<90, duration: 2.0)
}
let rainbow = Gradient(.red, .green, .blue, .red)
ledStrip.sequence {
ledStrip.threatreChase(.red, repeatCount: 30)
ledStrip.threatreChase(rainbow, repeatCount: 30)
}
ledStrip.repeatForever {
ledStrip.animate(Color(red: 200, green: 0, blue: 0), duration: 3.0, curve: .easeOut)
ledStrip.animate(Color(red: 20, green: 0, blue: 0), duration: 3.0, curve: .easeIn)
}
ledStrip.popcorn(Color(red: 255, green: 0, blue: 0), averagePopsPerSecond: 6, averagePopDuration: 0.6)
- WS2812 / WS2812b (aka NeoPixel)
- Raspberry Pi 1/2/3/4
- Install Swift on your Raspberry Pi (https://github.com/uraimo/buildSwiftOnARM) or (https://lickability.com/blog/swift-on-raspberry-pi/)
- Create swift project with a dependency for this package