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[] = "d5c5f04f802f445c8c918cac3b387f48";
// Set your LED and physical button pins here
const int ledPin1 = A0;
const int btnPin1 = 4;
const int ledPin2 = A1;
const int btnPin2 = 5;
const int ledPin3 = A2;
const int btnPin3 = 6;
const int ledPin4 = A3;
const int btnPin4 = 7;
const int ledPin5 = A4;
const int btnPin5 = 8;
const int ledPin6 = A5;
const int btnPin6 = 9;
const int ledPin7 = 2;
const int btnPin7 = 10;
const int ledPin8 = 3;
const int btnPin8 = 11;
BlynkTimer timer;
void checkPhysicalButton();
int ledState1 = LOW;
int btnState1 = HIGH;
int ledState2 = LOW;
int btnState2 = HIGH;
int ledState3 = LOW;
int btnState3 = HIGH;
int ledState4 = LOW;
int btnState4 = HIGH;
int ledState5 = LOW;
int btnState5 = HIGH;
int ledState6 = LOW;
int btnState6 = HIGH;
int ledState7 = LOW;
int btnState7 = HIGH;
int ledState8 = LOW;
int btnState8 = HIGH;
// Every time we connect to the cloud...
BLYNK_CONNECTED() {
// Request the latest state from the server
Blynk.syncVirtual(V2);
Blynk.syncVirtual(V3);
Blynk.syncVirtual(V4);
Blynk.syncVirtual(V5);
Blynk.syncVirtual(V6);
Blynk.syncVirtual(V7);
Blynk.syncVirtual(V8);
Blynk.syncVirtual(V9);
// Alternatively, you could override server state using:
//Blynk.virtualWrite(V2, ledState);
}
// When App button is pushed - switch the state
BLYNK_WRITE(V2) {
ledState1 = param.asInt();
digitalWrite(ledPin1, ledState1);
}
BLYNK_WRITE(V3) {
ledState2 = param.asInt();
digitalWrite(ledPin2, ledState2);
}
BLYNK_WRITE(V4) {
ledState3 = param.asInt();
digitalWrite(ledPin3, ledState3);
}
BLYNK_WRITE(V5) {
ledState4 = param.asInt();
digitalWrite(ledPin4, ledState4);
}
BLYNK_WRITE(V6) {
ledState5 = param.asInt();
digitalWrite(ledPin5, ledState5);
}
BLYNK_WRITE(V7) {
ledState6 = param.asInt();
digitalWrite(ledPin6, ledState6);
}
BLYNK_WRITE(V8) {
ledState7 = param.asInt();
digitalWrite(ledPin7, ledState7);
}
BLYNK_WRITE(V9) {
ledState8 = param.asInt();
digitalWrite(ledPin8, ledState8);
}
void checkPhysicalButton()
{ //FOR BUTTON1
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(V2, ledState1);
}
btnState1 = LOW;
} else {
btnState1 = HIGH;
}
//FOR BUTTON2
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(V3, ledState2);
}
btnState2 = LOW;
} else {
btnState2 = HIGH;
}
//FOR BUTTON3
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(V4, ledState3);
}
btnState3 = LOW;
} else {
btnState3 = HIGH;
}
//FOR BUTTON4
if (digitalRead(btnPin4) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState4 != LOW) {
// Toggle LED state
ledState4 = !ledState4;
digitalWrite(ledPin4, ledState4);
// Update Button Widget
Blynk.virtualWrite(V5, ledState4);
}
btnState4 = LOW;
} else {
btnState4 = HIGH;
}
//FOR BUTTON5
if (digitalRead(btnPin5) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState5 != LOW) {
// Toggle LED state
ledState5 = !ledState5;
digitalWrite(ledPin5, ledState5);
// Update Button Widget
Blynk.virtualWrite(V6, ledState5);
}
btnState5 = LOW;
} else {
btnState5 = HIGH;
}
//FOR BUTTON6
if (digitalRead(btnPin6) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState6 != LOW) {
// Toggle LED state
ledState6 = !ledState6;
digitalWrite(ledPin6, ledState6);
// Update Button Widget
Blynk.virtualWrite(V7, ledState6);
}
btnState6 = LOW;
} else {
btnState6 = HIGH;
}
//FOR BUTTON7
if (digitalRead(btnPin7) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState7 != LOW) {
// Toggle LED state
ledState7 = !ledState7;
digitalWrite(ledPin7, ledState7);
// Update Button Widget
Blynk.virtualWrite(V8, ledState7);
}
btnState7 = LOW;
} else {
btnState7 = HIGH;
}
//FOR BUTTON8
if (digitalRead(btnPin8) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState8 != LOW) {
// Toggle LED state
ledState8 = !ledState8;
digitalWrite(ledPin8, ledState8);
// Update Button Widget
Blynk.virtualWrite(V9, ledState8);
}
btnState8 = LOW;
} else {
btnState8 = HIGH;
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
// You can also specify server:
//Blynk.begin(auth, "blynk-cloud.com", 8442);
//Blynk.begin(auth, IPAddress(192,168,1,100), 8442);
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, ledState3);
pinMode(ledPin4, OUTPUT);
pinMode(btnPin4, INPUT_PULLUP);
digitalWrite(ledPin4, ledState4);
pinMode(ledPin5, OUTPUT);
pinMode(btnPin5, INPUT_PULLUP);
digitalWrite(ledPin5, ledState5);
pinMode(ledPin6, OUTPUT);
pinMode(btnPin6, INPUT_PULLUP);
digitalWrite(ledPin6, ledState6);
pinMode(ledPin7, OUTPUT);
pinMode(btnPin7, INPUT_PULLUP);
digitalWrite(ledPin7, ledState7);
pinMode(ledPin8, OUTPUT);
pinMode(btnPin8, INPUT_PULLUP);
digitalWrite(ledPin8, ledState8);
// Setup a function to be called every 100 ms
timer.setInterval(100L, checkPhysicalButton);
}
void loop()
{
Blynk.run();
timer.run();
}
You can help me, I can not make it work