Hi guys, I have a problem with my project. i cant sync my buttons with the blynk app. only two buttons work, if I press the other two buttons,arduino go offline, this is the sketch;
THANK YOU FOR YOUR HELP!
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
char auth[] = "0000000000000000000";
#define W5100_CS 10
#define SDCARD_CS 4
const int ledPin = 7;
const int btnPin = 8;
const int ledPin1 = 6;
const int btnPin1 = 9;
const int ledPin2 = 2;
const int btnPin2 = 13;
const int ledPin3 = 3;
const int btnPin3 = 12;
int ledState = LOW;
int btnState = HIGH;
int ledState1 = LOW;
int btnState1 = HIGH;
int ledState2 = LOW;
int btnState2 = HIGH;
int ledState3 = LOW;
int btnState3 = HIGH;
BLYNK_CONNECTED() {
Blynk.syncVirtual(V2);
Blynk.syncVirtual(V1);
Blynk.syncVirtual(V8);
Blynk.syncVirtual(V9);
}
BLYNK_WRITE(V2) {
ledState = param.asInt();
digitalWrite(ledPin, ledState);
}
BLYNK_WRITE(V1) {
ledState1 = param.asInt();
digitalWrite(ledPin1, ledState1);
}
BLYNK_WRITE(V8) {
ledState2 = param.asInt();
digitalWrite(ledPin2, ledState2);
}
BLYNK_WRITE(V9) {
ledState3 = param.asInt();
digitalWrite(ledPin3, ledState3);
}
BlynkTimer timer;
void checkPhysicalButton()
{
if (digitalRead(btnPin) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState != LOW) {
// Toggle LED state
ledState = !ledState;
digitalWrite(ledPin, ledState);
// Update Button Widget
Blynk.virtualWrite(V2, ledState);
}
btnState = LOW;
} else {
btnState = HIGH;
}
if (digitalRead(btnPin1) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState1 != LOW) {
// Toggle LED state
ledState1 = !ledState1;
digitalWrite(ledPin1, ledState1);
// Update Button Widget
Blynk.virtualWrite(V1, ledState1);
}
btnState1 = LOW;
} else {
btnState1 = HIGH;
}
if (digitalRead(btnPin2) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState2 != LOW) {
// Toggle LED state
ledState2 = !ledState2;
digitalWrite(ledPin2, ledState2);
// Update Button Widget
Blynk.virtualWrite(V8, ledState2);
}
btnState2 = LOW;
} else {
btnState2 = HIGH;
}
if (digitalRead(btnPin3) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState3 != LOW) {
// Toggle LED state
ledState3 = !ledState3;
digitalWrite(ledPin3, ledState3);
// Update Button Widget
Blynk.virtualWrite(V9, ledState3);
}
btnState3 = LOW;
} else {
btnState3 = HIGH;
}
}
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH);
Blynk.begin(auth);
pinMode(ledPin, OUTPUT);
pinMode(btnPin, INPUT_PULLUP);
digitalWrite(ledPin, ledState);
pinMode(ledPin1, OUTPUT);
pinMode(btnPin1, INPUT_PULLUP);
digitalWrite(ledPin1, ledState1);
pinMode(ledPin2, OUTPUT);
pinMode(btnPin2, INPUT_PULLUP);
digitalWrite(ledPin2, ledState2);
pinMode(ledPin3, OUTPUT);
pinMode(btnPin3, INPUT_PULLUP);
digitalWrite(ledPin3, ledState);
timer.setInterval(100L, checkPhysicalButton);
}
void loop()
{
Blynk.run();
timer.run();
}