Suggestions

you are right !!!

No, I should have a red vLED when the real LED is off then a green vLED when the real LED is on. But now since I’ve corrected count they’re either both on or both off.

Well I was hoping it would turn off one vLED while turning on the other vLED and visa versa. This was my idea of a simple array exercise … :anguished:

but the for next statement is not necessary
better code like that, else you will flood blynk a little if you have more relays

/*************** buttons *********************/
BLYNK_WRITE(V1)
{
  RelayBTN1 = param.asInt();
  if (RelayBTN1 == true) {
    digitalWrite(relay1, ON);
    led10.on();
    led11.off();

  }
  else {
    digitalWrite(relay1, OFF);
    led10.off();
    led11.on();
  }
}

one of the problems i see, is this:
WidgetLED led[] = {10, 11};

this is not correct (actually, i do not understand why it even compiles?)

the “widgetled” is a constructor for an object. afaik, it can’t accept arrays… @Fettkeewl, what do you think?

you are mixing things up a bit:
the arrays are variables, not objects. it should be declared as bool, byte, int, Srting, etc.

1 Like

the array exercise you choose with the leds is a bit unfortunate. i thought you would better exercise with the 8 channel relay board. maybe…

you can declare a byte array with 8 elements, and fill it up with the gpio of every relay. (this also will not work very well because of the “special” features of esp pins. but if you choose carefully it is doable.)

then, you can exercise with:

  • create a button in the app to toggle all relays at once, create a for cycle and turn on / off all relays in a row, iterating through the elements of the array

  • create a dedicated button in the app for every relay, and turn on off the relays with: if (parameters as int) digitalwrite(myarray[index of gpio])

ps. sorry for the mess, i’m on phone.

1 Like

It certainly was. Just another noob error that I hope to avoid in the future.

That’s exactly what I’ve been doing for the past few hours, with a bit more success I’m pleased to say. Admittedly I’ve had a little help but my understanding of arrays is a hundred times better than it was yesterday.

So thanks for the heads up.

I’ve learnt a lot the past few days. :wink:

and this was the aim of the topic, right?

@Shadeyman, if you are interested more seriously in coding, the best thing i can recommend is this free book, by the great professor Allen B. Downey. this is by far the most user friendly and logically arranged book i’ve ever read… and yes, it is looong, so do not expect to finish in a week! if you follow carefully and do all the exercises, it will skyrocket - not only your coding skills - but your general problem solving and coding strategies. granted!

i recommend to print the book chapter by chapter, as you progress and use active reading strategies!

1 Like

Exactly. To push my limits and learn. Admittedly my limits are easily pushed so thank you for the link to Downey’s book. I’ll transfer it to my Kindle for some bedtime reading.

1 Like

great! if you actually do the exercises from the book and run into roadblocks, open a dedicated topic in the lounge and we can discuss there, to avoid non blynk related topics here :wink:

1 Like

The topic is Blynk related, I plan to use 16 relays, 8 water pumps, 8 coloured LED lights and Blynk to control a dancing fountain. The “array” part was an off shoot started by yourself. I’ve learnt loads and most of the stuff hasn’t even been delivered yet …

no, i meant if you have problems regarding the exercies from the book.

1 Like