🛠 Pilote le NeoPixel embarqué (broche D13)

Adafruit Feather nRF52840 Express · intermediaire · Schéma : IMG-nrf52840-feather-intermediaire-2-nrf52840-neopixel-d13.svg — Gros plan sur le NeoPixel d'état de la Feather nRF52840, broche D13 et alimentation 3,3 V commandées depuis la broche data, ruban de couleurs d'exemple.

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials