I have this sketch that runs properly (almost) of one with Arduino Ethernet shield
void loop(){ Blynk.run(); signalLed(); } void signalLed(){ if (timeElapsed > interval){ for(int i=0; i<index; i++){ stato[i] = digitalRead(pinR[i]); } if ((stato [0])== LOW){ led1.off(); }else{ led1.on(); } if ((stato [1])== LOW){ led2.off(); }else{ led2.on(); } if ((stato [2])== LOW){ led3.off(); }else{ led3.on(); } if ((stato [3])== LOW){ led4.off(); }else{ led4.on(); } timeElapsed = 0; } }
I have found that by feeding Arduino, just connected to the server, for a brief moment Led1 goes ON and then back to off. Because?
In the app I placed 4 buttons with switch function and the log is this
37345] Ready (ping: 33ms).
[37355] msg 17,1,96
ver.0.3.4.h-beat.10.buff-in.256.dev.Arduino.cpu.ATmega328P.con.W5100.build.Jun 28 2016 13:41:59.
[37483] msg 20,125,26pm.4.out.5.out.6.out.7.out
[37536] msg 20,2,8
vw.1.255
[37570] msg 20,3,6
vw.2.0
[37601] msg 20,4,6
vw.3.0
[37632] msg 20,5,6
vw.4.0
[37663] msg 0,1,200
Why this?
vw.1.255
Franchelli:
Why this?
where is the rest of your code?
#define BLYNK_PRINT Serial BLYNK
#define BLYNK_DEBUG
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <elapsedMillis.h>
elapsedMillis timeElapsed;
#define index 4 // definisce il numero di pin di uscita
int pinR[index]= {4,5,6,7}; // numerazione pin uscita
int pinOk = 8; // stato avvenuta connessione
int interval = 3000; // intervallo di polling stato uscite x visualizzzione
int stato[index]; // array dova salvare letture ingressi
char auth[] = ".....";
byte arduino_mac[] = { 0x1C, 0xFC, 0x31, 0xDD, 0x3D, 0xCA };
IPAddress arduino_ip ( ......);
IPAddress dns_ip ( 8, 8, 8, 8);
IPAddress gateway_ip ( 193,206,154,001);
IPAddress subnet_mask(255, 255, 255,0);
WidgetLED led1(V0); //registrazione al pin virtuale V0
WidgetLED led2(V1); //registrazione al pin virtuale V1
WidgetLED led3(V2); //registrazione al pin virtuale V2
WidgetLED led4(V3); //registrazione al pin virtuale V3
void setup(){
pinMode(pinOk, OUTPUT);
for(int i=0; i<index-1; i++){
pinMode(pinR[i], INPUT_PULLUP);
}
Serial.begin(9600);
Blynk.begin(auth, "blynk-cloud.com", 8442, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
while (Blynk.connect() == false) {
}
digitalWrite(pinOk, HIGH);
}
void loop(){
Blynk.run();
signalLed();
}
void signalLed(){
if (timeElapsed > interval){
for(int i=0; i<index; i++){
stato[i] = digitalRead(pinR[i]);
}
if ((stato [0])== LOW){
led1.off(); on V1 OFF
}else{
led1.on();
}
if ((stato [1])== LOW){
led2.off();
}else{
led2.on();
}
if ((stato [2])== LOW){
led3.off();
}else{
led3.on();
}
if ((stato [3])== LOW){
led4.off();
}else{
led4.on();
}
timeElapsed = 0;
}
}
BLYNK_CONNECTED(){
Blynk.syncAll();
}
No idea about it ?
Someone can help me?
Sorry, but it is really hard to know exactly what you are asking about?
Can you please be more specific?
Instead of making up your own timer, try the SimpleTimer library. It’s better to use with Blynk. The PushData example from the Blynk library has an excellent example of how to use it.