FastLED 3.9.15
Loading...
Searching...
No Matches
Spi.ino
Go to the documentation of this file.
1// Multi-lane SPI example for FastLED
2// Demonstrates using 4 independent SPI lanes to drive 4 LED strips
3// @filter (mem is large)
4
5#include "FastLED.h"
6#include "fl/log/log.h"
7
8#define CLOCK_PIN 3
9
10// Use explicit array initialization (AVR compiler requires this)
11int pins[] = {0, 1, 2, 5};
12
14
15void setup() {
16 Serial.begin(115200);
17
18
19 if (!spi_device.ok()) {
20 FL_WARN("SPI device failed to initialize!" << spi_device.error());
21 } else {
22 FL_DBG("SPI device initialized with 4 lanes");
23 }
24}
25
26void loop() {
27 if (!spi_device.ok()) {
28 FL_WARN("SPI device was not initialized!");
29 delay(1000);
30 return;
31 }
32
33 // Example data for each lane - all lanes must have the same size
34 // Using C arrays and manual initialization for AVR compatibility
35 static const uint8_t lane0[] = {0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
36 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00};
37 static const uint8_t lane1[] = {0xAA, 0x55, 0xAA, 0x00, 0x00, 0x00, 0x00, 0x00,
38 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
39 static const uint8_t lane2[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
40 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
41 static const uint8_t lane3[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
42 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
43
44
45 // Simple API - write all 4 lanes at once (starts transmission asynchronously)
46 auto result = spi_device.write(lane0, lane1, lane2, lane3);
47 if (!result.ok) {
48 FL_WARN("Write failed: " << result.error);
49 delay(1000);
50 return;
51 }
52
53 // Wait for transmission to complete (blocks until done)
54 spi_device.wait();
55
56 FL_DBG("Data transmitted to 4 lanes");
57
58 // Delay before next transmission
59 delay(100);
60}
fl::Spi spi_device(CLOCK_PIN, pins, fl::spi_output_mode_t::SPI_HW)
void setup()
Definition Spi.ino:15
int pins[]
Definition Spi.ino:11
void loop()
Definition Spi.ino:26
SPI Device - RAII wrapper for multi-lane SPI.
Definition spi.h:53
#define FL_WARN(X)
Definition log.h:276
#define FL_DBG
Definition log.h:388
Centralized logging categories for FastLED hardware interfaces and subsystems.
@ SPI_HW
Use DMA-capable hardware (Async or Sync), supports 1/2/4/8 lanes depending on platform.
Definition config.h:27
#define Serial
Definition serial.h:304