Preparación de las Prácticas con FastLED&Esp32&Blynk

Expongo los elementos utilizados para la realización de prácticas con la librería FastLED que publico en otro post:

Mesa de trabajo:

  • Placa: Esp32
  • Dos columnas en paralelo de strips Leds de 143 elementos,de los que uso 140
  • Hardware virtual con la App Blynk(versión antigua)
  • Pantalla TFT para lecturas
  • Dos reguladores DC to DC LM2596
  • App Blynk(antigua versión)

Plantilla Sketch sin instrucciones a ejecutar:

#include <FastLED.h>
#include <OneButton.h>
#define PIN_LEFT     13
#define PIN_RIGHT     14
#define NUM_LEDS    140
#define BTN_PIN   15 
CRGB leds[NUM_LEDS];
#include "SPI.h"
#include "TFT_eSPI.h"
#define TFT_GREY 0x7BEF
// Use hardware SPI
TFT_eSPI tft = TFT_eSPI();
 #include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char auth[] = "1mepQ9UdDKFOkOxw8fqpqkyChIJYyDB7";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "atom_2.4g";
char pass[] = "crixalcfilos";



///////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t patternCounter = 0;
uint8_t hue = 0;
int v1;
int v2;
int slidert1;
int slidert2;
int stepper;
///////////////////////////////////////////////////////////////////////////////////////


BlynkTimer timer1; // Announcing the timer1
void Readvalue()
{
//int  v3 = readvalue;         // declaramos una variable que tiene la información requerida
//  Blynk.virtualWrite(V3, v3);  //
}

BLYNK_WRITE(V0){
  slidert1=param.asInt();
}
BLYNK_WRITE(V1){
  v1 = param.asInt();
}
  BLYNK_WRITE(V2){
  v2 = param.asInt(); 
  }
  BLYNK_WRITE(V4){
 slidert2 = param.asInt(); 
  }
  BLYNK_WRITE(V5){
 stepper = param.asInt(); 
  }
 
void nextPattern() {
  patternCounter = (patternCounter + 1) % 4;   
}

//pin controlado por la App aa GPio 15 con valor=1 en reposo y valor 0 en activo,equivalente
//a dar GND al pulsar
OneButton btn = OneButton(BTN_PIN, true, true);

void setup() {
 
 Blynk.begin(auth, ssid, pass);
  tft.begin();
  tft.setRotation(3);
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_WHITE);  // color de texto en blanco
  tft.setTextSize(3);     // escala de texto en 2
  tft.setCursor(100, 100);    // ubica cursor en esquina superior izquierda
  tft.print("FastLED");  // imprime texto
  FastLED.addLeds<NEOPIXEL, PIN_LEFT>(leds, NUM_LEDS);
  FastLED.addLeds<NEOPIXEL, PIN_RIGHT>(leds, NUM_LEDS);
  FastLED.setBrightness(10);
 FastLED.clear();
FastLED.show();
      Serial.begin(9600);
//   btn.attachClick(nextPattern); 
//timer1.setInterval(1000L, Readvalue); //timer will run every sec
}
 

void loop() {
     Blynk.run();
      FastLED.setBrightness(slidert2);
 // timer1.run();
  if  (v1==1){
 //instrucciones
 FastLED.show();
 btn.tick();
}
 
  else if (v1==0&&v2==0){  FastLED.clear();   FastLED.show();
}
 if  (v2==1){
   
//instrucciones
 FastLED.show();
 btn.tick();
 }
  } 

  

ELEMENTOS BASICOS:

Definición de librerias y hardware:

Declaramos un array y dos strips trabajando en espejo:



CRGB leds[NUM_LEDS];


void setup(){
........
 FastLED.addLeds<NEOPIXEL, PIN_LEFT>(leds, NUM_LEDS);
  FastLED.addLeds<NEOPIXEL, PIN_RIGHT>(leds, NUM_LEDS);
.....

Uso de la pantalla TFT:

Podriamos obviar este elemento, pero nos puede ayudar a visualizar algunas lecturas



#include "SPI.h"
#include "TFT_eSPI.h"
#define TFT_GREY 0x7BEF
// Use hardware SPI
TFT_eSPI tft = TFT_eSPI();

void setup(){
......


tft.begin();
  tft.setRotation(3);
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_WHITE);  // color de texto en blanco
  tft.setTextSize(3);     // escala de texto en 2
  tft.setCursor(100, 100);    // ubica cursor en esquina superior izquierda
  tft.print("FastLED");  // imprime texto

.........

Uso de Blynk:

Comentamos el timer1 para ser utilizado cuando se necesite.


 #include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char auth[] = "-----------";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "atom_2.4g";
char pass[] = "----------";



void setup(){
......



 Blynk.begin(auth, ssid, pass);

//timer1.setInterval(1000L, Readvalue); //timer will run every sec

Declaración de variables , pines virtuales y contador para enviar información a la app




///////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t patternCounter = 0;
uint8_t hue = 0;
int v1;
int v2;
int slidert1;
int slidert2;
int stepper;
///////////////////////////////////////////////////////////////////////////////////////



BlynkTimer timer1; // Announcing the timer1
void Readvalue()
{
//int  v3 = readvalue;         // declaramos una variable que tiene la información requerida
//  Blynk.virtualWrite(V3, v3);  //
}

BLYNK_WRITE(V0){
  slidert1=param.asInt();//variable controlada desde app
}
BLYNK_WRITE(V1){//boton V1 app
  v1 = param.asInt();
}
  BLYNK_WRITE(V2){//boton V2 app

  v2 = param.asInt(); 
  }
  BLYNK_WRITE(V4){
 slidert2 = param.asInt();//variable controlada desde app

  }
  BLYNK_WRITE(V5){
 stepper = param.asInt(); //variable controlada desde app


  }
 


//pin virtual V6 asociado a GPio 15 con valor=1 en reposo y valor 0 en activo,equivalente
//a dar GND al pulsar
OneButton btn = OneButton(BTN_PIN, true, true);



slidert2 va a controlar el brillo:



void loop() {
     Blynk.run();
      FastLED.setBrightness(slidert2);
 // timer1.run();

V1 y V2 son dos botones virtuales que nos serviran para diferentes instrucciones. Las variables slidert1 y stepper la usaremos para controlar algunas funciones de FastLED.

Tambien usaremos el software de la librería <onebutton.h>, en este caso asociado a la GPIO 15 del Esp32 y que pondremos a valor = 0 equivalente a dar a masa un pulsador conectado a dicho pin.

....

#define BTN_PIN   15 
OneButton btn = OneButton(BTN_PIN, true, true);
....

void nextPattern() {
  patternCounter = (patternCounter + 1) % 4;// Change the number after the % to the number of patterns you have
}

void setup(){
......
//   btn.attachClick(nextPattern);

.....
}
 void loop(){
.....
//no olvidar de incluir:


btn.tick();

}



Para usar este boton aqui pongo un ejemplo de uso con switch….case

 void loop(){
......
switch (patternCounter) {
    case 0:
      movingDots();
      break;
    case 1:
      rainbowBeat();
      break;
    case 2:
      redWhiteBlue();
      break;
      case 3:
      uint16_t sinBeat   = beatsin16(30, 0, NUM_LEDS - 1, 0, 0);
     leds[sinBeat]   = CRGB::Blue;
     fadeToBlackBy(leds, NUM_LEDS, 10);
      break;
   }
  
  FastLED.show();
  btn.tick();
}

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *