clignotante.ino

Particle Photon · File : clignotante.ino · Language : Arduino · Use case : Faire clignoter la LED D7 et publier l'état dans le cloud

The cloud-flavored blink: LED D7 blinks and two variables expose the state and counter to the Particle API. From the dashboard or curl, the board becomes remotely queryable with no extra network code.

Hardware

A Particle Photon module (2.4 GHz Wi-Fi, STM32 microcontroller, metal shielding) powered by USB or VIN. None: the user LED is built in. The Wi-Fi module embeds its antenna and metal shielding.

Wiring

Nothing to wire for LED D7. Power: USB or 3.6-5.5 V on VIN (3.3 V max on the pins).

How it works

In loop() we toggle D7 and update the variables exposed by Particle.variable; the cloud stack serves them on a plain HTTP request to the Particle API.

Running it

With the Particle CLI: particle flash --serial (DFU mode, double reset) or OTA flash once the board is online. Safe Mode (reset + WiFi) covers troubleshooting.

Variants

Drive the LED remotely with Particle.function, or blink on cloud state (PARTICLE_CONNECTED) as a network indicator.

clignotante.ino

// Clignotement D7 + suivi cloud via Particle.variable.
// La LED utilisateur de la carte est sur D7.

int etatLed = 0;
unsigned long compteur = 0;

// Expose l'etat a l'API cloud : GET /v3/devices/<id>/variables/etat
Particle.variable("etat", etatLed);
Particle.variable("cycles", compteur);

void setup() {
  pinMode(D7, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  etatLed = 1 - etatLed;
  digitalWrite(D7, etatLed);
  compteur++;
  Serial.println(etatLed ? "ON" : "OFF");
  delay(1000);
  // Particle.process() est appele en arriere-plan en mode AUTOMATIC :
  // le lien cloud reste vivant meme avec ce delay.
}

← Back to the board