Neopixel primo approccio con libreria FastLED

Per iniziare a programmare i LED Neopixel, prodotto inventato e distribuito da Adafruit, ho scaricato la libreria FastLED.

Copiando la libreria nella cartella delle librerie di Arduino automaticamente vengono caricati gli esempi. Per fare in modo che gli esempi funzionino è importante controllare ed eventualmente settare correttamente il pin a cui è collegato la linea seriale della striscia Neopixel ed il numero di led. Negli esempi viene usata la costante LED_PIN per indicare il Pin a cui collegare la striscia LED Neopixel mentre per il numero di Led viene usata la costante NUM_LEDS.

Nel repository GITHUB c’è la documentazione per capire come usare la libreria FastLED , per una documentazione completa della libreria FastLED fare riferimento a questo link.

 

Ho trovato molto interessante questa funzione:

 // limit my draw to 5W
   FastLED.setMaxPowerInMilliWatts(5000);

Come primo test per esplorare la libreria FastLED ho scritto il seguente codice per un a disco LED formato da 5 anelli.

disco-led

La parte posteriore del disco presente i contatti per le varie connessioni.

 

disco-led-back

Quindi nella figura di seguito i fili saldati alle piazzole.

disco-led-back-connections

Per testare il disco ho caricato uno sketch di prova ecco il risultato:

 

Il codice scritto è elementare è il primo passo per ottenere un primo risultato funzionante.

#include “FastLED.h”

FASTLED_USING_NAMESPACE

// This DemoRing scketch is to test neopixel ring consisting on five different rings
// for more details please refer to openprojects.altervista.org

#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
#warning “Requires FastLED 3.1 or later; check github for latest code.”
#endif

#define DATA_PIN 3
//#define CLK_PIN 4
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS 61
#define FIRST_RING 1
#define SECOND_RING 8
#define THIRD_RING 12
#define FOURTH_RING 16
#define FIFTH_RING 24

CRGB leds[NUM_LEDS];
int i;
int j;
int k;
int l;
int m;
#define BRIGHTNESS 30
#define FRAMES_PER_SECOND 120

void setup() {
delay(3000); // 3 second delay for recovery

// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

// set master brightness control
FastLED.setBrightness(BRIGHTNESS);
}

void loop()
{
// Light on the Frist Ring
for( i = 0; i < FIRST_RING; i++) {
leds[i] = CRGB::Red;
}
FastLED.show();
delay(500);

// Light off the Frist Ring
for( i = 0; i < FIRST_RING; i++) {
leds[i] = CRGB::Black;
}
FastLED.show();
delay(500);

// Light on the Second Ring
for( j = i; j < (i + SECOND_RING); j++) {
leds[j] = CRGB::Red;
}
FastLED.show();
delay(500);

// Light off the Second Ring
for( j = i; j < (i + SECOND_RING); j++) {
leds[j] = CRGB::Black;
}
FastLED.show();
delay(500);

// Light on the Third Ring
for( k = j; k < ( j + THIRD_RING); k++) {
leds[k] = CRGB::Red;
}
FastLED.show();
delay(500);

// Light off the Third Ring
for( k = j; k < ( j + THIRD_RING); k++){
leds[k] = CRGB::Black;
}
FastLED.show();
delay(500);

// Light on the Fourth Ring
for( l = k; l < (k + FOURTH_RING); l++) {
leds[l] = CRGB::Red;
}
FastLED.show();
delay(500);

// Light off the Fourth Ring
for( l = k; l < (k + FOURTH_RING); l++) {
leds[l] = CRGB::Black;
}
FastLED.show();
delay(500);

// Light on the Fifth Ring
for( m = l; m < (l + FIFTH_RING); m++) {
leds[m] = CRGB::Red;
}
FastLED.show();
delay(500);

// Light off the Fifth Ring
for( m = l; m < (l + FIFTH_RING); m++) {
leds[m] = CRGB::Black;
}
FastLED.show();
delay(500);
}

Ecco il risultato:

 

 

 

Offerte del giornoGuarda