I have three LEDs on Pins 14, 15, & 16.
I created three buttons in Blynk to turn them on individually.
I also have a virtual pin that blinks the three bulbs in unison by blinking pins 14, 15, 16.
If I press the Blynk buttons and light the LEDs first, everything works fine afterwards.
If I run the virtual pin function first before I ever press the Blynk buttons, the lights only light dimly.
This is because the pins were never defined in the sketch as outputs.
It seems the pins dont get defined until they are activated by a Blynk button press.
Is there a way that Blynk can define pins on startup…so I dont need to do it manually?
this is already happens when you press start button on dashboard. Please share your code so we could check it is ok. Also hardware restart may help. It could be a hardware issues itself.
it looks like you just forgot to set the pinModes in the setup() for your digital pins.
It’s always better to do so if you are calling digitalWrite from the virtual Pin
I thought one of the benefits of Blynk was that I didn’t need to define and setup pins within the sketch. I may as well define everything if I plan to call the pin functions from anything other than the Blynk app.
Can’t your app define pins used in the app when play is pressed?
it really does so (i.e setups pins).
But it really doesn’t matter as you use also a virtual pin handler (so you already modify code).
Why should it be hard to set pinModes in this case?
It really doesn’t matter in this case as it’s just a test of your system. And it’s not hard to define a pin as an output and set it to low in my setup. But I was under the impression that your app was supposed to do that for me.
I could add 12 buttons in your app to control 12 LEDs (or other devices). But if I want to create a virtual pin that creates an option to light two LEDs at once…I need to define my pins. Complicate that further and suddenly the advertised 5 minute simplicity of your app isn’t 5 minutes anymore.
A possible solution could be that your app defines any digital or analog pin, that is controlled by a button in the app, as an OUTPUT…after pressing play.
I think I have witnessed on my project what you were seeing. It seems like the output state can be defined but not necessarily in sync with the APP. After one cycle though, everything seems to be in order.
I know this didn’t really answer the question but perhaps verified what you are seeing.
I am using a 8 relay board and want to know exactly when those relays are energized because obviously they will be controlling real world things around my home. As I understand it, the attached code should immediately look at the D2 pin and copy that to V22. It does not. As an example using the attached code, set button V2 high and everything goes high. Hit the reset button and everything goes low, yet V2 remains high, V22 remains high. Blynk does not look at V22 to update. Button V2 has to cycle to LOW and then HIGH again before everything is in sync. State change requires some Event, related or unrelated.
char auth[] = "X"; // Put your Auth Token here. (see Step 3 above)
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth); // Here your Arduino connects to the Blynk Cloud.
// Reset all Arduino outputs to HIGH
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
pinMode(3, OUTPUT);
digitalWrite(3, HIGH);
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
pinMode(5, OUTPUT);
digitalWrite(5, HIGH);
pinMode(6, OUTPUT);
digitalWrite(6, HIGH);
pinMode(7, OUTPUT);
digitalWrite(7, HIGH);
pinMode(8, OUTPUT);
digitalWrite(8, HIGH);
pinMode(9, OUTPUT);
digitalWrite(9, HIGH);
int pinState2 = digitalRead(2);
Blynk.virtualWrite(22, pinState2);
}
BLYNK_WRITE(2)
{
int pinState2 = digitalRead(2);
Blynk.virtualWrite(22, pinState2);
if (param.asInt()) {
digitalWrite(2, LOW);
} else {
digitalWrite(2, HIGH);
}
}
BLYNK_WRITE(3)
{
if (param.asInt()) {
digitalWrite(3, LOW);
Blynk.virtualWrite(13, HIGH);
} else {
digitalWrite(3, HIGH);
Blynk.virtualWrite(13, LOW);
}
}
BLYNK_WRITE(4)
{
if (param.asInt()) {
digitalWrite(4, LOW);
Blynk.virtualWrite(14, HIGH);
} else {
digitalWrite(4, HIGH);
Blynk.virtualWrite(14, LOW);
}
}
BLYNK_WRITE(5)
{
if (param.asInt()) {
digitalWrite(5, LOW);
Blynk.virtualWrite(15, HIGH);
} else {
digitalWrite(5, HIGH);
Blynk.virtualWrite(15, LOW);
}
}
void loop()
{
Blynk.run(); // All the Blynk Magic happens here...
}