I am a little confused.
I would like a LED widget to reflect the state of a hardware pin. I do not want to use a timer to trigger the reading of the pin state. Instead I would like to know if there is an invisible widget which can perform this at specified interval and update the LED widget?
Thank you very much for your quick reply. The question is, how is updateLED() in your example called? As per the guidelines, it cannot sit in the loop function and if I do not use a timer loop then it will never be called. Why doesn’t the LED widget simply have a polling period like the “Value Display” widget.
The way I am currently doing it is to have a value dispaly which is set to every 10 sec and everytime it reads the value, on the hardware side I also return the “value” of the LED. This is why I was asking for an invisible widget doing periodic polls.
Ah, ok. There is no invisible widget with polling. Why LED has no polling interval? Well, LED itself is very limited in states it can represent (ON, OFF, +transparency) so from our point of view it was unnecessary (+additional development effort at that time =)).
This is one way. Also you could use timer approach if you don’t need value display.
LED widget was inspired by physical LED. It’s an output element, which means that it displays value. Since LED can’t request data, you have to send it to it.
In order to send data to LED, you need to write this logic. Unfortunately, due to the way Arduino works in combination with Internet you have to limit the number of outgoing messages. This is why timer is needed.
Otherwise, imagine 1000 devices sending 1000 messages in the loop. Thay would generate 1million requests per second to Blynk server, which is really hard to manage.
I understand your point but still I think you are not up to the promise of Blynk being simple.
Indeed, the “hello world” example of using Blynk and demonstrating its simplicity is to have a button widget on the App to switch a physical Led On or Off on the hardware. This is achieved by simply wiring a led on a physical pin on the hardware.
The reciprocal of this, keeping the Blynk motto of simplicity, would be to have a physical button wired to a pin on the hardware which switches a Led widget On or Off on the App.
The fact that you have to introduce a timer object to achieve this defeats the “simplicity” aspect of it.
Again, I think the simplest way of solving this is to have a Led widget with polling interval or an invisible widget which does the polling if you do not like a Led to do that.
On the examples above i cannot get the code right so this works on 2 hardware pins. Can anyone helpindent preformatted text by 4 spaces
/**************************************************************
* Blynk is a platform with iOS and Android apps to control
* Arduino, Raspberry Pi and the likes over the Internet.
* You can easily build graphic interfaces for all your
* projects by simply dragging and dropping widgets.
*
* Downloads, docs, tutorials: http://www.blynk.cc
* Blynk community: http://community.blynk.cc
* Social networks: http://www.fb.com/blynkapp
* http://twitter.com/blynk_app
*
* Blynk library is licensed under MIT license
* This example code is in public domain.
*
**************************************************************
* This example shows how to monitor a button state
* using interrupts mechanism.
*
* App dashboard setup:
* LED widget on V1
*
**************************************************************/
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "c865d8ce6f5341dd903170ee5ece8746";
void setup()
{
Serial.begin(9600);
Blynk.begin(auth);
// Make pin 2 HIGH by default
pinMode(2, INPUT_PULLUP);
// Attach INT to our handler
attachInterrupt(digitalPinToInterrupt(2), checkPin, CHANGE);
// Make pin 2 HIGH by default
pinMode(3, INPUT_PULLUP);
// Attach INT to our handler
attachInterrupt(digitalPinToInterrupt(3), checkPin, CHANGE);
}
void checkPin()
{
// Invert state, since button is "Active LOW"
int state = !digitalRead(2,3);
Blynk.virtualWrite(V1,V2, state);
}
void loop()
{
Blynk.run();
}
I’m not sure what your goal is, but this obviously doesn’t work.
/**************************************************************
* Blynk is a platform with iOS and Android apps to control
* Arduino, Raspberry Pi and the likes over the Internet.
* You can easily build graphic interfaces for all your
* projects by simply dragging and dropping widgets.
*
* Downloads, docs, tutorials: http://www.blynk.cc
* Blynk community: http://community.blynk.cc
* Social networks: http://www.fb.com/blynkapp
* http://twitter.com/blynk_app
*
* Blynk library is licensed under MIT license
* This example code is in public domain.
*
**************************************************************
* This example shows how to monitor a button state
* using interrupts mechanism.
*
* App dashboard setup:
* LED widget on V1
*
**************************************************************/
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "c865d8ce6f5341dd903170ee5ece8746";
void setup()
{
Serial.begin(9600);
Blynk.begin(auth);
// Make pin 2 HIGH by default
pinMode(2, INPUT_PULLUP);
// Attach INT to our handler
attachInterrupt(digitalPinToInterrupt(2), checkPin, CHANGE);
// Make pin 2 HIGH by default
pinMode(3, INPUT_PULLUP);
// Attach INT to our handler
attachInterrupt(digitalPinToInterrupt(3), checkPin, CHANGE);
}
void checkPin()
{
// Invert state, since button is "Active LOW"
int state1 = !digitalRead(2);
int state2 = !digitalRead(3);
Blynk.virtualWrite(V1, state1);
Blynk.virtualWrite(V2, state2);
}
void loop()
{
Blynk.run();
}
You have to address each virtual pin separately. This code will set the state to the two pins.
I would like to measure the level of a water tank and have It represented by LED widgets on blynk. I have proved the theory with one led and one hard wear pin but would now like to repeat it anothe 4 times. Although it maybe obvious to you that what I have done won’t work but it isn’t to me hence why I posted on the site! I don’t think it is very helpful saying this obviously won’t work! Not very community spirited!