Recherche et expérimentation artistique

Outils pour utilisateurs

Outils du site

Panneau latéral

[Code] Pure Data - WS2812 LEDs controle

Codes .pd et .ino permettant de sélectionner une led via PureData, de l'allumer ou de l'éteindre. Contrôle de l'intensitée lumineuse (fade).

Pure Data - FastLed test2

Teensy - FastLed test2

Teensy code, à utiliser avec le patch pd-fastled-test1.pd, il permet de sélectionner une LED et de l'allumer.Fade ou de changement de luminosité possible,

//à utiliser avec le patch serial-4-fastled.pd
// Use if you want to force the software SPI subsystem to be used for some reason (generally, you don't)
// Use if you want to force non-accelerated pin access (hint: you really don't, it breaks lots of things)
#include "FastLED.h"
// Move a white dot along the strip of leds.  This program simply shows how to configure the leds,
// and then how to turn a single pixel white and then off, moving down the line of pixels.
// How many leds are in the strip?
#define NUM_LEDS 47
// Data pin that led data will be written out over
#define DATA_PIN 14
// Clock pin only needed for SPI based chipsets when not using hardware SPI
//#define CLOCK_PIN 8
// This is an array of leds.  One item for each led in your strip.
// Set up a CHSV color
// This function sets up the ledsand tells the controller about them
String inputString = "";   // chaine de caractères pour contenir les données
boolean stringComplete = false;  // pour savoir si la chaine est complète
int pix;
void setup() {
// sanity check delay - allows reprogramming if accidently blowing power w/leds
// Uncomment one of the following lines for your leds arrangement.
// FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
// FastLED.addLeds<APA104, DATA_PIN>(leds, NUM_LEDS);
// FastLED.addLeds<WS2811_400, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD8806, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<P9813, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<APA102, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<DOTSTAR, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// This function runs over and over, and is where you do the magic to light
// your leds.
void loop() {
  // 2 - Utilisation du message
  if (stringComplete) {
    // on récupère la position du séparateur (l'espace " ")
    int index = inputString.indexOf(' ');
    // on coupe la chaine en deux : la fonction d'un côté et l'argument de l'autre
    String fct = inputString.substring(0, index);
    String arg = inputString.substring(index, inputString.length());
    // appel de ma fonction en transformant la chaine en nombre
    if (fct == "FADELED") {
      light(13, arg.toInt());
    else if (fct == "NLED") {
      light(9, arg.toInt());
    // on vide la chaine pour utiliser les messages suivants
    inputString = "";
    stringComplete = false;
    // deuxième découpage pour le second argument
    index = arg.lastIndexOf(' ');
    String arg2 = arg.substring(index, arg.length());
    arg = arg.substring(0, index);
    // appel des fonctions en transformant la chaine en nombre
    if (fct == "LED") {
      light(arg.toInt(), arg2.toInt());
    else if (fct == "MODE") {
      mode(arg.toInt(), arg2.toInt());
void serialEvent() {
  while (Serial.available()) {
    // récupérer le prochain octet (byte ou char) et l'enlever
    char inChar = (char)Serial.read();
    // concaténation des octets reçus
    inputString += inChar;
    // caractère de fin pour notre chaine
    if (inChar == '\n') {
      stringComplete = true;
// fonction personnalisable
void light(int pin, int brightness) {
  leds[pin] = CRGB::HotPink;
  // Show the leds (only one of which is set to white, from above)
  // Wait a little bit
  // delay(500);
  // Turn our current led back to black for the next loop around
  //leds[pix] = CRGB::Black;
  //Serial.print("Light function : ");
  //Serial.print(", ");
  //analogWrite(pin, brightness);
void mode(int pin2, int brightness) {
  leds[pin2] = CRGB::HotPink;
  // Show the leds (only one of which is set to white, from above)

Codes : pd-fastled-test1.zip

Pure Data - Neopixel test1

Teensy - Neopixel test1

Teensy code, à utiliser avec le patch pd-neopixel-test.pd, il permet de sélectionner une LED et de l'allumer. Pas de fade ou de changement de luminosité, ou de couleur pour l'instant.

// A utiliser avec le patch pd-neopixel-test.pd
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN            14
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      47
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
//int delayval = 10; // delay for half a second
int incomingByte = 0;   // for incoming serial data
void setup() {
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  pixels.begin(); // This initializes the NeoPixel library.
void loop() {
  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(incomingByte, pixels.Color(250, 0, 250)); // Moderately bright green color.
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
    pixels.setPixelColor(incomingByte, pixels.Color(10, 0, 10));

Codes : pd-neopixel-test.zip

prod/recherches/code/pd-pixel-tests.txt · Dernière modification: 17 12 2019 (modification externe)