Eclairage RGB pilotable pour porte latéral d’ordinateur source Adafruit

Eclairage RGB pilotable pour porte latéral d’ordinateur source Adafruit

Vous avez envie d’avoir un belle éclairage variable dans votre tour d’ordinateur, rien de plus simple, un arduino, un ruban de led RGB WS2801 ou LPD8806 😉
Basé sur le projet Adalight de Adafruit
https://learn.adafruit.com/adalight-diy-ambient-tv-lighting?view=all

  1. Connexion

    3 fils seront a connecté sur l'arduino,
    - Gnd (masse)
    -pin 13 (spi clock)
    -pin 11 (spi MOSI)

    l'alimentation de votre ruban de led se fera via une prise molex de votre ordinateur ( 5V fil rouge ou 12V file jaune suivant votre ruban de led) via un adaptateur en Y.

    l'arduino utilisera son câble USB pour être alimenté, programmé et contrôlé.
  2. Voici le code arduino pour des led WS2801

    Source arduino Afafruit https://github.com/adafruit/Adafruit-X2-Time-Ball/blob/master/Arduino/LEDstream/LEDstream.pde

    // Arduino "bridge" code between host computer and WS2801-based digital
    // RGB LED pixels (e.g. Adafruit product ID #322). Intended for use
    // with USB-native boards such as Teensy or Adafruit 32u4 Breakout;
    // works on normal serial Arduinos, but throughput is severely limited.
    // LED data is streamed, not buffered, making this suitable for larger
    // installations (e.g. video wall, etc.) than could otherwise be held
    // in the Arduino's limited RAM.

    // Some effort is put into avoiding buffer underruns (where the output
    // side becomes starved of data). The WS2801 latch protocol, being
    // delay-based, could be inadvertently triggered if the USB bus or CPU
    // is swamped with other tasks. This code buffers incoming serial data
    // and introduces intentional pauses if there's a threat of the buffer
    // draining prematurely. The cost of this complexity is somewhat
    // reduced throughput, the gain is that most visual glitches are
    // avoided (though ultimately a function of the load on the USB bus and
    // host CPU, and out of our control).

    // LED data and clock lines are connected to the Arduino's SPI output.
    // On traditional Arduino boards, SPI data out is digital pin 11 and
    // clock is digital pin 13. On both Teensy and the 32u4 Breakout,
    // data out is pin B2, clock is B1. LEDs should be externally
    // powered -- trying to run any more than just a few off the Arduino's
    // 5V line is generally a Bad Idea. LED ground should also be
    // connected to Arduino ground.

    // --------------------------------------------------------------------
    // This file is part of Adalight.

    // Adalight is free software: you can redistribute it and/or modify
    // it under the terms of the GNU Lesser General Public License as
    // published by the Free Software Foundation, either version 3 of
    // the License, or (at your option) any later version.

    // Adalight is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    // GNU Lesser General Public License for more details.

    // You should have received a copy of the GNU Lesser General Public
    // License along with Adalight. If not, see
    // .
    // --------------------------------------------------------------------

    #include

    // LED pin for Adafruit 32u4 Breakout Board:
    //#define LED_DDR DDRE
    //#define LED_PORT PORTE
    //#define LED_PIN _BV(PORTE6)
    // LED pin for Teensy:
    //#define LED_DDR DDRD
    //#define LED_PORT PORTD
    //#define LED_PIN _BV(PORTD6)
    // LED pin for Arduino:
    #define LED_DDR DDRB
    #define LED_PORT PORTB
    #define LED_PIN _BV(PORTB5)

    // A 'magic word' (along with LED count & checksum) precedes each block
    // of LED data; this assists the microcontroller in syncing up with the
    // host-side software and properly issuing the latch (host I/O is
    // likely buffered, making usleep() unreliable for latch). You may see
    // an initial glitchy frame or two until the two come into alignment.
    // The magic word can be whatever sequence you like, but each character
    // should be unique, and frequent pixel values like 0 and 255 are
    // avoided -- fewer false positives. The host software will need to
    // generate a compatible header: immediately following the magic word
    // are three bytes: a 16-bit count of the number of LEDs (high byte
    // first) followed by a simple checksum value (high byte XOR low byte
    // XOR 0x55). LED data follows, 3 bytes per LED, in order R, G, B,
    // where 0 = off and 255 = max brightness.

    static const uint8_t magic[] = {'A','d','a'};
    #define MAGICSIZE sizeof(magic)
    #define HEADERSIZE (MAGICSIZE + 3)

    #define MODE_HEADER 0
    #define MODE_HOLD 1
    #define MODE_DATA 2

    // If no serial data is received for a while, the LEDs are shut off
    // automatically. This avoids the annoying "stuck pixel" look when
    // quitting LED display programs on the host computer.
    static const unsigned long serialTimeout = 15000; // 15 seconds

    void setup()
    {
    // Dirty trick: the circular buffer for serial data is 256 bytes,
    // and the "in" and "out" indices are unsigned 8-bit types -- this
    // much simplifies the cases where in/out need to "wrap around" the
    // beginning/end of the buffer. Otherwise there'd be a ton of bit-
    // masking and/or conditional code every time one of these indices
    // needs to change, slowing things down tremendously.
    uint8_t
    buffer[256],
    indexIn = 0,
    indexOut = 0,
    mode = MODE_HEADER,
    hi, lo, chk, i, spiFlag;
    int16_t
    bytesBuffered = 0,
    hold = 0,
    c;
    int32_t
    bytesRemaining;
    unsigned long
    startTime,
    lastByteTime,
    lastAckTime,
    t;

    LED_DDR |= LED_PIN; // Enable output for LED
    LED_PORT &= ~LED_PIN; // LED off

    Serial.begin(115200); // Teensy/32u4 disregards baud rate; is OK!

    SPI.begin();
    SPI.setBitOrder(MSBFIRST);
    SPI.setDataMode(SPI_MODE0);
    SPI.setClockDivider(SPI_CLOCK_DIV16); // 1 MHz max, else flicker

    // Issue test pattern to LEDs on startup. This helps verify that
    // wiring between the Arduino and LEDs is correct. Not knowing the
    // actual number of LEDs connected, this sets all of them (well, up
    // to the first 1,000, so as not to be TOO time consuming) to red,
    // green, blue, then off. Once you're confident everything is working
    // end-to-end, it's OK to comment this out and reprogram the Arduino.
    uint8_t testcolor[] = { 0, 0, 0, 255, 0, 0 };
    for(char n=3; n>=0; n--) {
    for(c=0; c serialTimeout) {
    for(c=0; c= HEADERSIZE) {
    // Indeed. Check for a 'magic word' match.
    for(i=0; (i 0) and multiply by 3 for R,G,B.
    bytesRemaining = 3L * (256L * (long)hi + (long)lo + 1L);
    bytesBuffered -= 3;
    spiFlag = 0; // No data out yet
    mode = MODE_HOLD; // Proceed to latch wait mode
    } else {
    // Checksum didn't match; search resumes after magic word.
    indexOut -= 3; // Rewind
    }
    } // else no header match. Resume at first mismatched byte.
    bytesBuffered -= i;
    }
    break;

    case MODE_HOLD:

    // Ostensibly "waiting for the latch from the prior frame
    // to complete" mode, but may also revert to this mode when
    // underrun prevention necessitates a delay.

    if((micros() - startTime) 0) {
    if(bytesBuffered > 0) {
    SPDR = buffer[indexOut++]; // Issue next byte
    bytesBuffered--;
    bytesRemaining--;
    spiFlag = 1;
    }
    // If serial buffer is threatening to underrun, start
    // introducing progressively longer pauses to allow more
    // data to arrive (up to a point).
    if((bytesBuffered bytesBuffered)) {
    startTime = micros();
    hold = 64 + (32 - bytesBuffered) * 4;
    mode = MODE_HOLD;
    }
    } else {
    // End of data -- issue latch:
    startTime = micros();
    hold = 1000; // Latch duration = 1000 uS
    LED_PORT |= LED_PIN; // LED on
    mode = MODE_HEADER; // Begin next header search
    }
    } // end switch
    } // end for(;;)
    }

    void loop()
    {
    // Not used. See note in setup() function.
    }
  3. Code demo processing source Adafruit https://github.com/adafruit/Adalight/blob/master/Processing/Colorswirl/Colorswirl.pde

    // "Colorswirl" LED demo. This is the host PC-side code written in
    // Processing; intended for use with a USB-connected Arduino microcontroller
    // running the accompanying LED streaming code. Requires one strand of
    // Digital RGB LED Pixels (Adafruit product ID #322, specifically the newer
    // WS2801-based type, strand of 25) and a 5 Volt power supply (such as
    // Adafruit #276). You may need to adapt the code and the hardware
    // arrangement for your specific configuration.

    // --------------------------------------------------------------------
    // This file is part of Adalight.

    // Adalight is free software: you can redistribute it and/or modify
    // it under the terms of the GNU Lesser General Public License as
    // published by the Free Software Foundation, either version 3 of
    // the License, or (at your option) any later version.

    // Adalight is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    // GNU Lesser General Public License for more details.

    // You should have received a copy of the GNU Lesser General Public
    // License along with Adalight. If not, see
    // .
    // --------------------------------------------------------------------

    import processing.serial.*;

    int N_LEDS = 25; // Max of 65536

    void setup()
    {
    byte[] buffer = new byte[6 + N_LEDS * 3];
    Serial myPort;
    int i, hue1, hue2, bright, lo, r, g, b, t, prev, frame = 0;
    long totalBytesSent = 0;
    float sine1, sine2;

    noLoop();

    // Assumes the Arduino is the first/only serial device. If this is not the
    // case, change the device index here. println(Serial.list()); can be used
    // to get a list of available serial devices.
    myPort = new Serial(this, Serial.list()[0], 115200);

    // A special header / magic word is expected by the corresponding LED
    // streaming code running on the Arduino. This only needs to be initialized
    // once because the number of LEDs remains constant:
    buffer[0] = 'A'; // Magic word
    buffer[1] = 'd';
    buffer[2] = 'a';
    buffer[3] = byte((N_LEDS - 1) >> 8); // LED count high byte
    buffer[4] = byte((N_LEDS - 1) & 0xff); // LED count low byte
    buffer[5] = byte(buffer[3] ^ buffer[4] ^ 0x55); // Checksum

    sine1 = 0.0;
    hue1 = 0;
    prev = second(); // For bandwidth statistics

    for (;;) {
    sine2 = sine1;
    hue2 = hue1;

    // Start at position 6, after the LED header/magic word
    for (i = 6; i > 8) % 6) {
    case 0:
    r = 255;
    g = lo;
    b = 0;
    break;
    case 1:
    r = 255 - lo;
    g = 255;
    b = 0;
    break;
    case 2:
    r = 0;
    g = 255;
    b = lo;
    break;
    case 3:
    r = 0;
    g = 255 - lo;
    b = 255;
    break;
    case 4:
    r = lo;
    g = 0;
    b = 255;
    break;
    default:
    r = 255;
    g = 0;
    b = 255 - lo;
    break;
    }

    // Resulting hue is multiplied by brightness in the range of 0 to 255
    // (0 = off, 255 = brightest). Gamma corrrection (the 'pow' function
    // here) adjusts the brightness to be more perceptually linear.
    bright = int(pow(0.5 + sin(sine2) * 0.5, 2.8) * 255.0);
    buffer[i++] = byte((r * bright) / 255);
    buffer[i++] = byte((g * bright) / 255);
    buffer[i++] = byte((b * bright) / 255);

    // Each pixel is slightly offset in both hue and brightness
    hue2 += 40;
    sine2 += 0.3;
    }

    // Slowly rotate hue and brightness in opposite directions
    hue1 = (hue1 + 4) % 1536;
    sine1 -= .03;

    // Issue color data to LEDs and keep track of the byte and frame counts
    myPort.write(buffer);
    totalBytesSent += buffer.length;
    frame++;

    // Update statistics once per second
    if ((t = second()) != prev) {
    print("Average frames/sec: ");
    print(int((float)frame / (float)millis() * 1000.0));
    print(", bytes/sec: ");
    println(int((float)totalBytesSent / (float)millis() * 1000.0));
    prev = t;
    }
    }
    }

    void draw()
    {
    }
  4. code processing adafruit modifié par moi plusieurs mode disponible ,off, statique, swirt et random swirt avec réglage de le couleur via sliders.


    // "Colorswirl" LED demo. This is the host PC-side code written in
    // Processing; intended for use with a USB-connected Arduino microcontroller
    // running the accompanying LED streaming code. Requires one strand of
    // Digital RGB LED Pixels (Adafruit product ID #322, specifically the newer
    // WS2801-based type, strand of 25) and a 5 Volt power supply (such as
    // Adafruit #276). You may need to adapt the code and the hardware
    // arrangement for your specific configuration.

    // --------------------------------------------------------------------
    // This file is part of Adalight.

    // Adalight is free software: you can redistribute it and/or modify
    // it under the terms of the GNU Lesser General Public License as
    // published by the Free Software Foundation, either version 3 of
    // the License, or (at your option) any later version.

    // Adalight is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    // GNU Lesser General Public License for more details.

    // You should have received a copy of the GNU Lesser General Public
    // License along with Adalight. If not, see
    // .
    // --------------------------------------------------------------------

    import processing.serial.*; // importe la librairie série processing

    import controlP5.*; // importe la librairie GUI controlP5

    ControlP5 controlP5; // déclare un objet principal de la librairie GUI controlP5

    Slider sRouge, sVert, sBleu; // déclare un/ des objet Slider

    // déclaration variables globales
    //------ déclaration des variables de couleur utiles ----
    int jaune=color(255,255,0);
    int vert=color(0,255,0);
    int rouge=color(255,0,0);
    int bleu=color(0,0,255);
    int noir=color(0,0,0);
    int blanc=color(255,255,255);
    int bleuclair=color(0,255,255);
    int violet=color(255,0,255);


    int N_LEDS = 52; // Max of 65536
    int mode =0;



    int randcolor, colorswirt ,i, hue1, hue2, bright, lo, t,r,g,b, prev, frame = 0;
    long totalBytesSent = 0;
    float sine1, sine2;
    byte[] buffer = new byte[6 + N_LEDS * 3];
    Serial myPort;
    // PImage bg;

    void setup()
    {
    // bg = loadImage("rog.jpg"); image de fond optionel

    // ---- initialisation paramètres graphiques utilisés
    colorMode(RGB, 255,255,255); // fixe format couleur R G B pour fill, stroke, etc...
    fill(bleu); // couleur remplissage RGB
    stroke (noir); // couleur pourtour RGB
    rectMode(CORNER); // origine rectangle : CORNER = coin sup gauche | CENTER : centre
    imageMode(CORNER); // origine image : CORNER = coin sup gauche | CENTER : centre
    //strokeWeight(0); // largeur pourtour
    // frameRate(150);// Images par seconde

    // --- initialisation fenêtre de base ---
    size(400, 400); // ouvre une fenêtre xpixels x ypixels
    // background(bg); image de fond optionel

    //======== Initialisation Objets GUI ControlP5 =========

    controlP5 = new ControlP5(this); // initialise l'objet principal de la librairie GUI controlP5

    // typeObjet nomObjet=controlP5.addObjet(paramètres); // pour info : déclaration / initialisation possible en 1 ligne
    // Textfield field = controlP5.addTextfield("myWindowTextfield",70,130,100,20); // exemple

    //======== Initialisation Objets Sliders =========
    // create a new button with name 'buttonA'
    controlP5.addButton("OFF")
    .setValue(0)
    .setPosition(300,10)
    .setSize(100,19)
    ;

    controlP5.addButton("SingleColor")
    .setValue(0)
    .setPosition(300,30)
    .setSize(100,19)
    ;

    controlP5.addButton("SwirtRan")
    .setValue(0)
    .setPosition(300,50)
    .setSize(100,19)
    ;

    controlP5.addButton("Swirt")
    .setValue(0)
    .setPosition(300,70)
    .setSize(100,19)
    ;


    controlP5.addButton("RotateRED")
    .setValue(0)
    .setPosition(300,130)
    .setSize(100,19)
    ;

    //------------ slider Rouge ----------------
    // addSlider(theName, theMin, theMax, theDefaultValue, theX, theY, theW, theH)
    sRouge=controlP5.addSlider("sRouge",0,255,255,10,10,50,350); // ajoute un Slider au ControlP5
    //s1 = (Slider)controlP5.controller("MonSlider1"); // initialise l'objet Slider déclaré

    // méthodes propres à l'objet Slider
    sRouge.setNumberOfTickMarks(256); // fixe le nombre crans - n+1 pour n valeurs
    //s1.setNumberOfTickMarks((int(s1.max())+1); // fixe le nombre crans - n+1 pour n valeurs
    sRouge.showTickMarks(false); // affichage des repères
    sRouge.setSliderMode(Slider.FIX); // fonctionnement du slider FLEXIBLE ou FIX

    // méthodes communes à tous les controles (objet Controller)
    sRouge.setLabelVisible(true); // affichage des labels
    sRouge.setLabel("ROUGE"); // fixe label objet
    sRouge.setDecimalPrecision(0); // fixe la précision
    sRouge.setColorActive(rouge); // fixe la couleur active
    //sRouge.setColorBackground(color(255,255,0)); // fixe couleur fond
    sRouge.setColorForeground(rouge); // fixe couleur avant
    //sRouge.setArrayValue(new float[] {100,255} ); // fixe les valeurs min/max du Slider ?
    sRouge.setColorCaptionLabel(blanc); // fixe couleur Label
    sRouge.setColorValueLabel(noir); // fixe la couleur valeur

    //------------ slider VERT ----------------
    // addSlider(theName, theMin, theMax, theDefaultValue, theX, theY, theW, theH)
    sVert=controlP5.addSlider("sVert",0,255,255,80,10,50,350); // ajoute un Slider au ControlP5
    //s1 = (Slider)controlP5.controller("MonSlider1"); // initialise l'objet Slider déclaré

    // méthodes propres à l'objet Slider
    sVert.setNumberOfTickMarks(256); // fixe le nombre crans - n+1 pour n valeurs
    //s1.setNumberOfTickMarks((int(s1.max())+1); // fixe le nombre crans - n+1 pour n valeurs
    sVert.showTickMarks(false); // affichage des repères
    sVert.setSliderMode(Slider.FIX); // fonctionnement du slider FLEXIBLE ou FIX

    // méthodes communes à tous les controles (objet Controller)
    sVert.setLabelVisible(true); // affichage des labels
    sVert.setLabel("VERT"); // fixe label objet
    sVert.setDecimalPrecision(0); // fixe la précision
    sVert.setColorActive(vert); // fixe la couleur active
    //sRouge.setColorBackground(color(255,255,0)); // fixe couleur fond
    sVert.setColorForeground(vert); // fixe couleur avant
    //sRouge.setArrayValue(new float[] {100,255} ); // fixe les valeurs min/max du Slider ?
    sVert.setColorCaptionLabel(blanc); // fixe couleur Label
    sVert.setColorValueLabel(noir); // fixe la couleur valeur

    //------------ slider BLEU ----------------
    // addSlider(theName, theMin, theMax, theDefaultValue, theX, theY, theW, theH)
    sBleu=controlP5.addSlider("sBleu",0,255,255,150,10,50,350); // ajoute un Slider au ControlP5
    //s1 = (Slider)controlP5.controller("MonSlider1"); // initialise l'objet Slider déclaré

    // méthodes propres à l'objet Slider
    sBleu.setNumberOfTickMarks(256); // fixe le nombre crans - n+1 pour n valeurs
    //s1.setNumberOfTickMarks((int(s1.max())+1); // fixe le nombre crans - n+1 pour n valeurs
    sBleu.showTickMarks(false); // affichage des repères
    sBleu.setSliderMode(Slider.FIX); // fonctionnement du slider FLEXIBLE ou FIX

    // méthodes communes à tous les controles (objet Controller)
    sBleu.setLabelVisible(true); // affichage des labels
    sBleu.setLabel("BLEU"); // fixe label objet
    sBleu.setDecimalPrecision(0); // fixe la précision
    sBleu.setColorActive(bleu); // fixe la couleur active
    //sRouge.setColorBackground(color(255,255,0)); // fixe couleur fond
    sBleu.setColorForeground(bleu); // fixe couleur avant
    //sRouge.setArrayValue(new float[] {100,255} ); // fixe les valeurs min/max du Slider ?
    sBleu.setColorCaptionLabel(blanc); // fixe couleur Label
    sBleu.setColorValueLabel(noir); // fixe la couleur valeur


    // Assumes the Arduino is the first/only serial device. If this is not the
    // case, change the device index here. println(Serial.list()); can be used
    // to get a list of available serial devices.
    myPort = new Serial(this, Serial.list()[0], 115200);

    // A special header / magic word is expected by the corresponding LED
    // streaming code running on the Arduino. This only needs to be initialized
    // once because the number of LEDs remains constant:
    buffer[0] = 'A'; // Magic word
    buffer[1] = 'd';
    buffer[2] = 'a';
    buffer[3] = byte((N_LEDS - 1) >> 8); // LED count high byte
    buffer[4] = byte((N_LEDS - 1) & 0xff); // LED count low byte
    buffer[5] = byte(buffer[3] ^ buffer[4] ^ 0x55); // Checksum

    sine1 = 0.0;
    hue1 = 0;
    prev = second(); // For bandwidth statistics


    }



    void draw()
    {

    sine2 = sine1;
    hue2 = hue1;

    rect(300,200,100,100); // Drawing the rectangle
    fill(r,g,b);


    switch (mode){
    case 0:
    for (i = 6; i > 8) % 6) {
    case 0:
    r = 255;
    g = lo;
    b = 0;
    break;
    case 1:
    r = 255 - lo;
    g = 255;
    b = 0;
    break;
    case 2:
    r = 0;
    g = 255;
    b = lo;
    break;
    case 3:
    r = 0;
    g = 255 - lo;
    b = 255;
    break;
    case 4:
    r = lo;
    g = 0;
    b = 255;
    break;
    default:
    r = 255;
    g = 0;
    b = 255 - lo;
    break;
    }
    bright = int(pow(0.5 + sin(sine2) * 0.5, 2.8) * 255.0);
    buffer[i++] = byte((r * bright) / 255);
    buffer[i++] = byte((g * bright) / 255);
    buffer[i++] = byte((b * bright) / 255);

    // Each pixel is slightly offset in both hue and brightness
    hue2 += 40;
    sine2 += 0.3;
    }
    hue1 = (hue1 + 4) % 1536;
    sine1 -= .03;

    // Issue color data to LEDs and keep track of the byte and frame counts
    myPort.write(buffer);
    break;

    case 1:
    for (i = 6; i < buffer.length; ) {
    bright = int(pow(0.5 + sin(sine2) * 0.5, 2.8) * 255.0);
    buffer[i++] = byte((r * bright) / 255);
    buffer[i++] = byte((g * bright) / 255);
    buffer[i++] = byte((b * bright) / 255);

    // Each pixel is slightly offset in both hue and brightness
    hue2 += 40;
    sine2 += 0.3;
    }
    hue1 = (hue1 + 4) % 1536;
    sine1 -= .03;

    // Issue color data to LEDs and keep track of the byte and frame counts
    myPort.write(buffer);
    break;

    case 2:
    for (i = 6; i < buffer.length; ) {
    buffer[i++] = byte(r);
    buffer[i++] = byte(g);
    buffer[i++] = byte(b);

    }

    // Issue color data to LEDs and keep track of the byte and frame counts
    myPort.write(buffer);
    break;

    case 3:
    for (i = 6; i 8) % 6) {

    default:
    r = 255;
    g = 0;
    b = 0;
    break;



    }
    bright = int(pow(0.5 + sin(sine2) * 0.5, 2.8) * 255.0);
    buffer[i++] = byte((r * bright) / 255);
    buffer[i++] = byte((g * bright) / 255);
    buffer[i++] = byte((b * bright) / 255);

    // Each pixel is slightly offset in both hue and brightness
    hue2 += 40;
    sine2 += 0.3;
    }
    hue1 = (hue1 + 4) % 1536;
    sine1 -= .03;

    // Issue color data to LEDs and keep track of the byte and frame counts
    myPort.write(buffer);
    break;
    }
    }

    // XXXXXXXXXXXXXXXXXXXXXX Autres Fonctions XXXXXXXXXXXXXXXXXXXXXX

    // Gestion des évènements des objets GUI controlP5 ----

    //------ fonction gestion globale des évènements GUI controlP5
    public void controlEvent(ControlEvent theEvent) {
    //println(theEvent.controller().name());// affiche le nom de l'évènement
    }

    // ------ gestion évènement Slider ------
    void sRouge(int valeur) { // fonction évènement Slider de meme nom - reçoit la valeur
    println("Evènement Slider Rouge avec valeur = "+valeur);


    r=int(valeur);
    }

    // ------ gestion évènement Slider ------
    void sVert(int valeur) { // fonction évènement Slider de meme nom - reçoit la valeur
    println("Evènement Slider Vert avec valeur = "+valeur);

    g=int(valeur); // envoie la valeur suivie d'un saut de ligne sur le port Série


    }

    // ------ gestion évènement Slider ------
    void sBleu(int valeur) { // fonction évènement Slider de meme nom - reçoit la valeur
    println("Evènement Slider Vert avec valeur = "+valeur);

    b=int(valeur); // envoie la valeur suivie d'un saut de ligne sur le port Série

    }

    // function colorA will receive changes from
    // controller with name colorA
    public void OFF(int theValue) {
    println("a button event from colorA: "+theValue);
    mode=3;
    }

    // function colorA will receive changes from
    // controller with name colorA
    public void SingleColor(int theValue) {
    println("a button event from colorA: "+theValue);
    mode=2;
    }

    // function colorA will receive changes from
    // controller with name colorA
    public void SwirtRan(int theValue) {
    println("a button event from colorA: "+theValue);
    mode=0;
    }

    // function colorA will receive changes from
    // controller with name colorA
    public void Swirt(int theValue) {
    println("a button event from colorA: "+theValue);
    mode=1;
    }

    // function colorA will receive changes from
    // controller with name colorA
    public void RotateRED(int theValue) {
    println("a button event from colorA: "+theValue);
    mode=4;
    }

    public static byte [] rotateRightOne (byte[] buffer )
    { int f = 0 ;
    byte [] tabrot = new byte [buffer.length] ;
    for ( f = 6 ; f < ( buffer.length-1) ; f++ )
    {
    tabrot[f] = buffer[f+1] ;
    }
    tabrot [tabrot.length -1 ] = buffer[6] ;
    return tabrot;
    }

    //XXXXXXXXXXXXXXXXXX Fin du programme XXXXXXXXXXXXXXXXX
Réalisé par
Posté le
Univers
Programmation
Temps de fabrication
2h
Niveau de difficulté
Débutant
Matériel(s)
1
Arduino UNO
1
Ruban de x LED RGB WS2801 ou LPD8806
1
ralonge y molex (http://www.conrad.fr/ce/fr/product/1388914/Cble-rallonge-IDE-Renkforce-1x-Alimentation-IDE-mle-4-ples-2x-Alimentation-IDE-femelle-4-ples-?ref=list)
Outils
1
Fer à souder

Aucun commentaire. Soyez le premier à en écrire un !

Vous devez être connecté pour laisser un commentaire.