Привет. Пробовал разобраться сам, но не получается. Хочу сделать что-то на подобии сигнализации. У меня есть геркон (перемычка с магнитом), и она прицеплена на дверь. При открытии двери, срабатывает уведомление.
С этим всё просто:
… //строки кода для работы с blynk
#define magswitch 8
byte magvalue;
void setup()
{
…
pinMode(magswitch,INPUT);
…
}
void loop()
{
Blynk.run();
magvalue = digitalRead(magswitch);
Blynk.virtualWrite (V1, magvalue);
}
Ну и в самом приложении настроил Eventor – что если magvalue = 0, то выводить уведомление, что дверь открыта.
Проблема в том, что я хочу сделать это устройство по умнее. Я добавил кнопку на панель приложения, и хочу что бы при нажатии на кнопку (режим - ON), уведомления приходили при каждом открытии двери, а при режиме кнопки OFF, не приходили уведомления. Что-то на подобии Поставить на охрану, снять с охраны.
Пробовал делать через BLYNK_WRITE(vPIN) ,но тут оно вроде и работает, но функция работает таким образом что обновление информации, происходит, только тогда, когда изменилось значение кнопки, а мене ведь нужно, чтобы оно проверяло это значение постоянно.
Пример опроса кнопки:
BLYNK_WRITE(V2) //опрашиваю кнопку
{
if(param.asInt()==1) //если параметр == 1,…
{
Blynk.virtualWrite (V1, magvalue); //…то мы записываем в V1 значение переменной magvalue
}
else if (param.asInt()==0) //, а если == 0,…
{
Blynk.virtualWrite (V1, 1); //…то мы передаем в V1, значение 1, вне зависимости значения magvalue
}
}
Может моя логика не совсем логична, но это то что мне пришло в голову. Буду благодарен за советы.
-------------------------------ENG-------Google translate------------------------------------
Hey. Tried to understand myself, but it does not work. I want to do something in the likeness of signaling. I have a reed switch (a jumper with a magnet) and it is attached to the door. When the door is opened, a notification is triggered.
With this, everything is simple:
… // a line of code to work with blynk
… CODE
Well, in the application itself configured the Eventor - that if magvalue = 0, then output a notification that the door is open.
The problem is that I want to make this device smarter. I added a button to the application bar, and I want that when the button is clicked (the mode is ON), notifications come every time the door is opened, and when the button is OFF, no notifications are notified. Something in the likeness of Arm, disarm.
Tried to do through BLYNK_WRITE (vPIN), but here it like and works, but the function works in such a way that update of the information occurs only when the value of the button has changed, and it is necessary that it checks this value constantly.
Example of button polling:
BLYNK_WRITE(V2) // I query the button
{
if(param.asInt()==1) // if the parameter is == 1, ...
{
Blynk.virtualWrite (V1, magvalue); // ... then we write in V1 the value of the variable magvalue
}
else if (param.asInt()==0) //, and if == 0, ...
{
Blynk.virtualWrite (V1, 1); // ... then we pass to V1, a value of 1, regardless of the value of magvalue
}
}
Maybe my logic is not entirely logical, but this is what came into my head. I will be grateful for the advice.