So I made this simple project by hooking up all the items from the title, in the usual way (arduino to tip31 to led strip). And I have Blynk and zeRGBa setup, and it’s working fine. I was wondering, would it be possible to have a button or something to do what’s called a “fade” mode, basically, changing all 3 pin values from 0,0,0 to 255,255,255 slowly (or you know, showing the full RGB scale? Because most of the stuff I tried, it doesn’t let me mess with the pins RGB strip is on, since they’re “busy”. What would be a good and quick way to do this?
Without more detail on your app layout and the code on your Arduino, I can only guess… but I think you are directly controlling the Digital pins via the zeRGBa, If so, then you are correct that another widget is unable to link to those same pins. Instead you would have to use Virtual Pins and code your own fading routines to mix and match widget control options.
Thanks for your reply! I’m rather new to all this, but what I did was load sketch called Serial HC05-06 which came with Blynk and just burned it on there. And yeah, I am directly controlling the digital ones. If I understood you correctly I’d have a button to send 1/0 to virtual pin, which would call some additional code for the fading routine? If so, would I have to do anything else or would I just add a button and code that part, and switch between fade/zeRGBa whenever I select any of them? Rather, would I need a “fade mode/zeRGBa mode” slider/button as well?
Using the Virtual pins and a bit of code, you can use a whole combination of widgets to control the same RGB strip. The zeRGBa as you have it, or three sliders for individual intensity control of each colour or; a button/switch to activate a pre-programmed routine, etc.
Search this site for RGB and you will see many ideas and code snippets to experiment from.
Here are two ways to control an RGB LED using the zeRGBa (with virtual pins) and/or a Button/Switch to allow the accelerometer on your phone to change the colours, using BLYNK_WRITE() Functions - essentially loops that are called when the corresponding virtual pin is called.
Needs the zeRGBa widget set to merge mode on V0
The accelerometer widget in merge mode set to V1
A button or switch widget set to V2
And of course the usual setup and the basic Blynk void loop:
void loop()
{
Blynk.run();
}
I have just cut/pasted snippets and edited them together for this post… check for syntax errors
//===== zeRGBa RGB - BLYNK Funtion =====
BLYNK_WRITE(V0) // Needs zeRGBa widget in Merge Mode on pin V0.
{
Blynk.run();
int r = param[0].asInt(); // get a RED channel value.
int g = param[1].asInt(); // get a GREEN channel value.
int b = param[2].asInt(); // get a BLUE channel value.
analogWrite(RedP, r); // Write to RED RGB pin.
analogWrite(GrnP, g); // Write to GREEN RGB pin.
analogWrite(BluP, b); // Write to BLUE RGB pin.
}
//===== Accelerometer RGB - BLYNK Funtion (Works with V2 Button/Switch Funtion) =====
BLYNK_WRITE(V1) // Needs accelerometer widget in Merge Mode on pin V1 - Funtion runs when V1 Switch is active HIGH.
{
while (AccelSwitch == 1) // When active HIGH, run the following...
{
int r = param[0].asInt(); // get a RED channel value.
int g = param[1].asInt(); // get a GREEN channel value.
int b = param[2].asInt(); // get a BLUE channel value.
analogWrite(RedP, r); // Write to RED RGB pin.
analogWrite(GrnP, g); // Write to GREEN RGB pin.
analogWrite(BluP, b); // Write to BLUE RGB pin.
AccelSwitch = 0; // Set flag LOW
Blynk.syncVirtual(V2); // Check V2 swicth to see if finished or loop routine again.
Blynk.run(); // keep other functions running while controling RGB with accelerometer.
}
}
//===== Button/Switch - BLYNK Funtion (activates Accelerometer RGB Funtion) =====
BLYNK_WRITE(V2) // When this switch is active HIGH, it changes from RED to GREEN...
{
AccelSwitch = param.asInt(); // checks to see if V2 is HIGH or LOW (also used for Accelerometer RGB - BLYNK Funtion).
if (AccelSwitch == 0) { // if V2 is LOW, turn off RGB...
analogWrite(RedP, 0); // Turn off RED RGB pin.
analogWrite(GrnP, 0); // Turn off GREEN RGB pin.
analogWrite(BluP, 0); // Turn off BLUE RGB pin.
Blynk.setProperty(V2, "color", "#FF0000"); /// set Button/Switch colour to RED and continue with rest of code.
}
else { // set Button/Switch colour to GREEN and continue with rest of code.
Blynk.setProperty(V2, "color", "#00FF00");
}
}
That’s amazing, thank you! Now all I really need to do is make up some code for color fading and assign something like that to the v1 switch, and re-set zeRGBa to v0! That’s really awesome.