🛠 Pilote le NeoPixel embarqué (broche D13)
Objectives
Control the status NeoPixel soldered onto the Feather nRF52840 using the Adafruit_NeoPixel library: color, brightness, and a non-blocking "heartbeat" animation. The NeoPixel is powered at 3.3 V, and its data line is connected to the pin exposed by the BSP via PIN_NEOPIXEL; general documentation often refers to it as "D13".
Hardware
- 1× Adafruit Feather nRF52840 Express + micro-USB cable
- Adafruit NeoPixel library (Library Manager)
Full Code
// nrf52840-neopixel-d13.ino
#include <Adafruit_NeoPixel.h>
#define NEO_PIN PIN_NEOPIXEL // broche NeoPixel embarquee (alias courant D13)
Adafruit_NeoPixel neo(1, NEO_PIN, NEO_GRB + NEO_KHZ800);
uint32_t t0 = 0;
void setup {
neo.begin;
neo.setBrightness(40); // 40/255 : evite d'aveugler et menage la batterie
}
void loop {
uint32_t t = millis % 1600; // periode 1,6 s
float phase = t / 1600.0f * 2.0f * PI;
uint8_t pulse = (uint8_t)(60 + 195 * pow(sin(phase), 6)); // battement
neo.setPixelColor(0, neo.Color(pulse, pulse / 6, 0));
neo.show;
if (millis - t0 > 20) t0 = millis; // cadence ~50 fps sans delay
}
Expected Verification
The NeoPixel breathes in warm orange in a continuous loop, without harsh blinking. Barely touching the data pin (with a finger) causes no spurious resets with the code above, as no other WS2812 frame is emitted.
Common Errors
- Confusing the red LED and the NeoPixel: The simple red LED is NOT a NeoPixel; Adafruit pages contradict each other regarding its pin (3 vs 13), so prefer the NeoPixel as recommended by the documentation.
neo.showinside an interrupt or during BLE: The WS2812 frame requires tight timings that the SoftDevice may disrupt; emit it fromloop.- Brightness at 255 on battery: A NeoPixel at full white draws several tens of mA.
- Inverted color order:
NEO_GRBis the correct order for recent embedded NeoPixels; if red/green are inverted, tryNEO_RGB.
Other tutorials for this board
Code examples for this board
neopixel_pulsation.pyPythonled_bouton.pyPythonentrees_num.pyPythonanalogique_lumiere.pyPythonservo_pwm.pyPythonscanner_i2c.pyPython