Blynk Feather Delay() alternative

I’m porting my project to blynk.
Basically, its a garage door sensor bypass, and all it does is shorts out the contacts on a delay.
Problem is, Blynk tells me I shouldn’t use Delay()

Here is my project. Can someone give me an alternative?

/* 

garage door opener invisible beam receiver emulator
(use to bypass garage door opener optical beam sensor)

circuit:

  • 5vdc power provided to ATTiny via 7805 regulator across the ~6.4v supply provided by the opener’s safety sensor terminals.
  • the usual capacitors connected to the 7805 are plenty to provide uninterrupted power to the ATTiny85 while the supply voltage is being shunted.
  • gate of mosfet or transistor connected to pin 2 of ATTiny
  • source of mosfet connected to ground of power supply and terminal 2 of Liftmaster/Craftsman opener
  • drain of mosfet connected to terminal 3 of Liftmaster/Craftsman opener
    */

int pin = 2; // pin to which a transistor or mosfet gate is attached

void setup()
{
pinMode(pin, OUTPUT);
}

void loop()
{
// 6.5ms/.5ms code
digitalWrite(pin, HIGH); // shunt, then wait 0.5 milliseconds
delayMicroseconds(500);
digitalWrite(pin, LOW); // open, then wait 6.5 milliseconds
delay(6);
delayMicroseconds(500);
}

Thanks in advance.

Search this forum for BlynkTimer based alternatives to delays, examples, etc… also try to keep the main logic OUT of your void loop()… Anything running in the void loop() runs constantly… and if it takes too long to loop, it delays the Blynk.run() housekeeping and crashes your connection… thus the requirement of timers and timed functions.

There is also entire sections (links at top of this page) one of which is called Help Center that has answers to many common questions and issues like you are running into

Here is a brief excerpt from one:


Avoiding the void

:point_up: :fire: :warning: VERY IMPORTANT: You can’t send sensor data in your void loop()

– Why?
– Because Blynk sends data over the Internet, and when you put something into void loop(), your microcontroller will execute it :scream_cat: gazillion number of times. Which means that Blynk Cloud will be flooded with gazillion messages from your hardware.

And when Blynk Cloud notices that, it automatically :scissors:︎ cuts your connection. Sorry…

– OK, what should I do then?
– Send sensor data in intervals!

Using timers to send sensor data in intervals

There are lots of ways to send data in intervals, but here is a simple one. We recommend using a BlynkTimer for that. It’s included in Blynk Library Package, so if you installed Library correctly, you are all set.


http://docs.blynk.cc/#blynk-firmware-blynktimer1