Switch between Blynk and Arduino

I am currently working on a lamp (RGB) which can be controlled via the Blynk app.
So far everything works fine. It behaves the way it should.

However; I want to implement a button (hardware) that switches between a ‘smart mode’ in Blynk and an ‘offline mode’ where the lamp displays only a single colour (preset pin is turned HIGH).

When in Blynk, everything works. When I press the button, the preset colour is set HIGH. But the settings from the Blynk-app are still activated as well. The other way around; when the preset colour is HIGH and the Blynk mode is activated, the prest colour also remains.

In short; is there a way to switch between Blynk and my single preset colour and sort of ‘reset’ the other mode?

My sketch so far

`#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_SoftSer.h>
#include <BlynkSimpleShieldEsp8266_SoftSer.h>

// Set ESP8266 Serial object
#include <SoftwareSerial.h>
SoftwareSerial esp8266(11, 12); // RX, TX
ESP8266 wifi(esp8266);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "authorisation";

const int button = 2;

void setup()
{
  // Set console baud rate
    Serial.begin(19200);  
  delay(10);
  // Set ESP8266 baud rate
  esp8266.begin(19200);
  delay(10);


for(int pinNumber = 3; pinNumber <6; pinNumber++){
    pinMode(pinNumber,OUTPUT);
    digitalWrite(pinNumber, LOW);
  }
  
  pinMode(button, INPUT_PULLUP);

  Blynk.begin(auth, wifi, "SSID", "Password");
  }

void loop() {
  int buttonValue = digitalRead(button);
  
if(buttonValue == HIGH){
//  digitalWrite(3, LOW);
  Blynk.run();
  } else {                            
  digitalWrite(3, HIGH);
  }
}`

Yes, you could use the hardware input to run a Blynk.disconnect() call. Then it will disconnect from the Blynk server, you can do your standalone things and call to Blynk.connect() if you push the hardware button.

This is I think the way to go for your project.

Thank you for replying. The problem however is that all IO’s keep their state when switching to the other mode (when the button is pressed). They actually should reset assuming the loop starts again?

For example - the sketch sets pin 3 to HIGH. When Blynk starts (the button is pressed) this pin remains HIGH. While it actually should reset itself? Setting the pin LOW on forehand (uncommented in the above sketch) leaves the pin LOW for Blynk as well.

What I would like is:
Button not pressed - Reset all previously set IO’s to LOW and set IO’s according to the sketch (in this example; pin 3 HIGH)
Button pressed - Reset all previously set IO’s to LOW and run Blynk.

Is this possible in some way?

You could use the EEPROM to store the values and set them accordingly when starting Blynk again. Keep in mind however that the EEPROM has a limited lifetime, they can do about 100.000 write cycles.

Hi Bart,
You could do a verry basic thing, put all of your “standalone” parameters and fonctions inside a “if” loop and use a boolean value that you could set to 0 or 1 depending on witch one you would use.
You could also start your “if” loop with all the output settings that you need. And a good way to keep in memory the previous settings done by blynk is to do a “value a =digital.read()” of every output and if you use a boolean value, it only use one bit of memory. This could be the very first action to be done everytime you go to the standalone mode. That way, you will be able to work direct with inputs or computer via serial monitor and Blynk values will all be saved and you could set them back just before calling Blynk.begin!!!