ruban-neopixel.ino

Particle Boron · File : ruban-neopixel.ino · Language : Arduino · Use case : Piloter un ruban NeoPixel et changer le motif par événement cloud

A locally animated NeoPixel strip whose pattern changes remotely through a plain Particle.subscribe. It shows the Particle event model: the board acts alone yet stays drivable from any other device on the account.

Hardware

A Particle Boron module (nRF52840, Wi-Fi + Bluetooth LE, cellular variant where applicable) with on-board antenna. 1 strip of 12 NeoPixel LEDs + external 5 V supply.

Wiring

Data to A0 (330 Ω resistor), VCC to external 5 V, GND common with the board.

How it works

The core neopixel library generates the WS2812 frame; subscribe() calls changerMotif() whenever a "motif" event appears, and loop() adapts the animation without ever blocking.

Running it

Install the Particle CLI (particle setup), flash with particle flash --serial or OTA (particle flash <name> firmware.bin). The Device Cloud app or REST API complete the deployment.

Variants

Add parameter-driven patterns (color, speed), or sync several boards on the same event.

ruban-neopixel.ino

// Ruban NeoPixel 12 LED sur A0, motif changeable a distance.
#include "neopixel/neopixel.h"   // bibliotheque integree Particle

#define PIN_NEO A0
#define NB 12
#define TYPE NEO_GRB

Adafruit_NeoPixel ruban(NB, PIN_NEO, TYPE);
int motif = 0;

void changerMotif(String args) {
  motif = args.toInt() % 3;   // 0 = vague, 1 = plein, 2 = stroboscope
}

void setup() {
  ruban.begin();
  ruban.setBrightness(60);
  Particle.subscribe("motif", changerMotif, MY_DEVICES);
}

void loop() {
  static unsigned long t0 = 0;
  if (millis() - t0 < 60) return;
  t0 = millis();

  static int tete = 0;
  ruban.clear();
  if (motif == 0) {
    ruban.setPixelColor(tete, ruban.Color(0, 120, 255));
    ruban.setPixelColor((tete + 1) % NB, ruban.Color(0, 40, 90));
  } else if (motif == 1) {
    for (int i = 0; i < NB; i++) ruban.setPixelColor(i, ruban.Color(255, 60, 0));
  } else {
    if ((millis() / 250) % 2)
      for (int i = 0; i < NB; i++) ruban.setPixelColor(i, ruban.Color(255, 255, 255));
  }
  ruban.show();
  tete = (tete + 1) % NB;
}

// Declencher : Particle.publish("motif", "1", 60, PRIVATE);

← Back to the board