Hi
ok i managed to get something by looking in another post. (Menu widgets issues on Blynk 2.0). The part I corrected is this:
String MenuItem[5]={"rainbow","rainbowWithGlitter","confetti","sinelon","juggle"};
BLYNK_CONNECTED()
{
BlynkParamAllocated items(128);
for (int i=0;i<10;i++) items.add(MenuItem[i]);
Blynk.setProperty(V52, "labels", items);
}
BLYNK_WRITE(vPIN_MENU) { // Menu Widget on V52
int index = param.asInt();
switch (index)
{
case 0: {
gCurrentPatternNumber = 0;
break;
}
case 1: {
gCurrentPatternNumber = 1;
break;
}
case 2: {
gCurrentPatternNumber = 2;
break;
}
case 3: {
gCurrentPatternNumber = 3;
break;
}
case 4: {
gCurrentPatternNumber = 4;
break;
}
}
}
Effects work by clicking the name of the effect on the menu. I still miss one thing, to make the effects work I have to click the “manual” widget (vPIN_MANUAL). immediately the “rainbow” starts and I can then change the effect from the widget menu. I would like the effects to start when I click on one of them without clicking “manual” first. But the code is complicated for me and I don’t understand what to add to my vPIN_MENU to do this. Who can help me?
Here is all the code that still works and could be useful to someone:
int statopinmanuale = 0;
int varSpeed, varRainbowSpeed;
int testLEDnumber, varMemSave;
int arrayCurrent[5], arrayMemory1[5], arrayMemory2[5], arrayMemory3[5], arrayNightMemory[5];
WidgetTerminal terminal(vPIN_TERMINAL);
BlynkTimer timer;
CRGB leds[LED_NUMBER];
void setup() {
/*WiFi.mode(WIFI_STA);*/
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
timer.setInterval(20, inizio); //timer della routine iniziale ogni 20ms secondo
/*********** OTA *************/
/* ArduinoOTA.setHostname(Guapa);
ArduinoOTA.begin();
/******** BOOT VARS **********/
arrayCurrent[0, 255, 255, 255]; // Set starting sequence as rainbow mode
varSpeed = 100; // Start on 100 fps
varRainbowSpeed = 0; // Start stationary
/******** FASTLED ************/
FastLED.setMaxPowerInVoltsAndMilliamps(5, LED_LIMIT_MILLIAMPS);
FastLED.addLeds<LED_TYPE, DATA_PIN, LED_ARRANGE>(leds, LED_NUMBER);
/******** READY **************/
terminal.print(F("# Blynk v" BLYNK_VERSION ": "));
terminal.println(F(" Device started"));
terminal.flush();
}
// Elenco dei modelli da scorrere. Ciascuno è definito come una funzione separata di seguito
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle};
uint8_t gCurrentPatternNumber = 0; // Numero di indice di quale modello è corrente
uint8_t gHue = 0; // "colore di base" rotante utilizzato da molti dei modelli
String CurrentHexRGB() {
return String("#") + String(((long)leds[0].r << 16) | ((long)leds[0].g << 8 ) | (long)leds[0].b, HEX);
}
BLYNK_WRITE(vPIN_HUE) {
updateColours(arrayCurrent[0], param.asInt(), arrayCurrent[2], arrayCurrent[3]);
//Blynk.setProperty(vPIN_HUE, "color", CurrentHexRGB()); // colour step
}
BLYNK_WRITE(vPIN_SATURATION) {
updateColours(arrayCurrent[0], arrayCurrent[1], param.asInt(), arrayCurrent[3]);
//Blynk.setProperty(vPIN_HUE, "color", CurrentHexRGB()); // saturation
}
BLYNK_WRITE(vPIN_BRIGHTNESS) {
updateColours(arrayCurrent[0], arrayCurrent[1], arrayCurrent[2], param.asInt());
//Blynk.setProperty(vPIN_HUE, "color", CurrentHexRGB()); // brightness
}
BLYNK_WRITE(vPIN_FPS) {
varSpeed = param.asInt();
}
BLYNK_WRITE(vPIN_PRESET) {
nextPattern();
}
BLYNK_WRITE(vPIN_COLOUR_RED) {
updateColours(1, 0, 255, 255);
updateWidgets();
}
BLYNK_WRITE(vPIN_COLOUR_GREEN) {
updateColours(1, 80, 255, 255);
updateWidgets();
}
BLYNK_WRITE(vPIN_COLOUR_BLUE) {
updateColours(1, 152, 255, 255);
updateWidgets();
}
BLYNK_WRITE(vPIN_COLOUR_WHITE) {
updateColours(1, 255, 0, 255);
updateWidgets();
}
BLYNK_WRITE(vPIN_MANUAL) {
statopinmanuale = param.asInt();
updateColours(param.asInt(), arrayCurrent[1], arrayCurrent[2], arrayCurrent[3]);
updateWidgets();
}
BLYNK_WRITE(vPIN_SYNC_GHUE) {
gHue = 0;
varSpeed = 100;
terminal.println(" | Sync'd gHUE ");
terminal.flush();
}
BLYNK_WRITE(vPIN_OFF) {
updateColours(1, 255, 255, 0);
updateWidgets();
}
BLYNK_WRITE(vPIN_RAINBOWSPEED) {
varRainbowSpeed = param.asInt();
Blynk.virtualWrite(vPIN_RAINBOWSPEED, varRainbowSpeed);
}
String MenuItem[5]={"rainbow","rainbowWithGlitter","confetti","sinelon","juggle"};
BLYNK_CONNECTED()
{
BlynkParamAllocated items(128);
for (int i=0;i<10;i++) items.add(MenuItem[i]);
Blynk.setProperty(V52, "labels", items);
}
BLYNK_WRITE(vPIN_MENU) { // Menu Widget on V52
int index = param.asInt();
switch (index)
{
case 0: {
gCurrentPatternNumber = 0;
break;
}
case 1: {
gCurrentPatternNumber = 1;
break;
}
case 2: {
gCurrentPatternNumber = 2;
break;
}
case 3: {
gCurrentPatternNumber = 3;
break;
}
case 4: {
gCurrentPatternNumber = 4;
break;
}
}
}
BLYNK_WRITE(vPIN_NIGHTMODE) {
if (param.asInt()) {
arrayNightMemory[arrayCurrent[0], arrayCurrent[1], arrayCurrent[2], arrayCurrent[3]];
updateColours(1, 152, 255, 100);
updateWidgets();
} else {
updateColours(arrayNightMemory[0], arrayNightMemory[1], arrayNightMemory[2], arrayNightMemory[3]);
updateWidgets();
}
}
void updateColours(int m, int h, int s, int b) {
arrayCurrent[0] = m;
arrayCurrent[1] = h;
arrayCurrent[2] = s;
arrayCurrent[3] = b;
}
void updateWidgets() {
Blynk.virtualWrite(vPIN_MANUAL, arrayCurrent[0]);
Blynk.virtualWrite(vPIN_HUE, arrayCurrent[1]);
Blynk.virtualWrite(vPIN_SATURATION, arrayCurrent[2]);
Blynk.virtualWrite(vPIN_BRIGHTNESS, arrayCurrent[3]);
//Blynk.setProperty(vPIN_HUE, "color", CurrentHexRGB());
}
/****************************************************************************/
void loop(){
Blynk.run();
timer.run();
}
void inizio()
{
switch (arrayCurrent[0]) {
case 1:
fill_solid(leds, LED_NUMBER, CHSV(arrayCurrent[1], arrayCurrent[2], arrayCurrent[3]));
break;
/*case 2:
FastLED.clear();
for (int led = 0; led < testLEDnumber; led++) leds[led] = CRGB::Blue;
break;*/
default:
gPatterns[gCurrentPatternNumber]();
EVERY_N_MILLISECONDS( 20 ) gHue++; // slowly cycle the "base color" through the rainbow
break;
}
FastLED.show();
}
/****************************************************************************/
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
void nextPattern() {
gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE(gPatterns);
}
void rainbow() {
// FastLED's built-in rainbow generator
fill_rainbow( leds, LED_NUMBER, gHue, varRainbowSpeed);
FastLED.delay(1000 / varSpeed);
}
void rainbowWithGlitter() {
// built-in FastLED rainbow, plus some random sparkly glitter
rainbow();
addGlitter(80);
}
void addGlitter( fract8 chanceOfGlitter) {
if ( random8() < chanceOfGlitter) leds[ random16(LED_NUMBER) ] += CRGB::White;
FastLED.delay(1000 / varSpeed);
}
void confetti() {
// random colored speckles that blink in and fade smoothly
fadeToBlackBy( leds, LED_NUMBER, 10);
int pos = random16(LED_NUMBER);
leds[pos] += CHSV( gHue + random8(64), 200, 255);
FastLED.delay(1000 / varSpeed);
}
void sinelon() {
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, LED_NUMBER, 20);
int pos = beatsin16(13, 0, LED_NUMBER);
leds[pos] += CHSV( gHue, 255, 192);
FastLED.delay(1000 / varSpeed);
}
void juggle() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, LED_NUMBER, 20);
byte dothue = 0;
for ( int i = 0; i < 8; i++) {
leds[beatsin16(i + 7, 0, LED_NUMBER)] |= CHSV(dothue, 200, 255);
dothue += 32;
}
FastLED.delay(1000 / varSpeed);
}
Thank you everyone