I’d never looked at (or attempted to use) virtual pins 128 - 255 until @Blynk_Coeur brought it up in a related topic. It’s a well-known fact @Blynk_Coeur is a virtual pin addict … he simply can’t get enough of them.
It is obvious from src/Blynk/BlynkHandlers.h that BLYNK_READ and BLYNK_WRITE don’t support virtual pins 128 – 255. What isn’t obvious is the recommendation to use BLYNK_READ_DEFAULT and BLYNK_WRITE_DEFAULT. @Gunner pointed out this is clearly called out in the Blynk documentation,
Kudos to the development team for documenting this. I understand (and agree with) the rationale for not wanting to extend the BLYNK_READ and BLYNK_WRITE support, burning additional program memory, given most users don’t need 256 virtual pins (except @Blynk_Coeur, of course).
I’ve never cared for the BLYNK_READ and BLYNK_WRITE macros. They have no type-checking nor range-checking. For example, this code compiles just fine and you’re left troubleshooting why your BLYNK_WRITE and BLYNK_READ macros aren’t being invoked,
#define BUTTON 0
#define VALUE_DISPLAY 33
BLYNK_WRITE(JUNK) {} // Note: this compiles, yet "JUNK is undefined
BLYNK_READ(JUNK) {} // Note: this compiles, yet "JUNK is undefined
BLYNK_WRITE(BUTON) { } // Note: this compiles, yet "BUTTON" is misspelled
BLYNK_READ(VALUE_DISPLY) { } // Note: this compiles, yet "VALUE_DISPLAY" is misspelled
BLYNK_WRITE(128) { } // Note: this compiles, yet virtual pin 128 is not supported
BLYNK_READ(128) { } // Note: this compiles, yet virtual pin 128 is not supported
Rather than use BLYNK_READ / BLYNK_WRITE for virtual pins 0 - 127 and BLYNK_READ_DEFAULT / BLYNK_WRITE_DEFAULT for virtual pins 128 - 255, I’m going to eliminate my use of BLYNK_READ and BLYNK_WRITE altogether.
I’m compiling out support for BLYNK_READ and BLYNK_WRITE in conjunction with virtual pins 32 - 127 in order to free up the unused program memory,
Here’s the complete test firmware …
Help: If anyone could help me figure out how to include Blynk\BlynkDetectDevice.h without specifying the absolute path I would appreciate it.
#define BLYNK_PRINT Serial
/*
* Use this first set of #includes, #defines and #undefs to compile out and free up the
* program memory used by BLYNK_READ and BLYNK_WRITE with virtual pins 32 - 127
*
* Note: Expect the following warning,
*
* #warning "Please include a board-specific header file, instead of Blynk.h (see examples)"
*/
#include <ESP8266WiFi.h>
#define BlynkApi_h
#include <Blynk.h>
#undef BlynkApi_h
#include <Blynk\BlynkDetectDevice.h>
#undef BLYNK_USE_128_VPINS
#include <BlynkSimpleEsp8266.h>
/*
* Otherwise, use this second set of #includes
*/
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "xxx";
char ssid[] = "xxx";
char pass[] = "xxx";
/*
* Controller Widget Virtual Pins
*/
#define BUTTON 0
#define SLIDER 32
#define TEXT_INPUT 128
#define NUMERIC_INPUT 254
/*
* Display Widget Virtual Pins
*/
#define LEVEL_V 1
#define VALUE_DISPLAY 33
#define LABELED_VALUE 129
#define LEVEL_H 255
/*
* Display Widget Test Values
*/
int level_v = LEVEL_V;
int value_display = VALUE_DISPLAY;
int labeled_value = LABELED_VALUE;
int level_h = LEVEL_H;
/*
* Controller Widget Virtual Pin Functions
*/
void inline blynk_write_button(BlynkParam param) {
Serial.printf("blynk_write_button: %s\n", param.asString());
}
void inline blynk_write_slider(BlynkParam param) {
Serial.printf("blynk_write_slider: %s\n", param.asString());
}
void inline blynk_write_text_input(BlynkParam param) {
Serial.printf("blynk_write_text_input: %s\n", param.asString());
}
void inline blynk_write_numeric_input(BlynkParam param) {
Serial.printf("blynk_write_numeric_input: %s\n", param.asString());
}
BLYNK_READ_DEFAULT(){
int pin = request.pin;
switch(pin) {
case LEVEL_V: Blynk.virtualWrite(pin, level_v); break;
case VALUE_DISPLAY: Blynk.virtualWrite(pin, value_display); break;
case LABELED_VALUE: Blynk.virtualWrite(pin, labeled_value); break;
case LEVEL_H: Blynk.virtualWrite(pin, level_h); break;
default:
Serial.printf("BLYNK_READ_DEFAULT: V%d Unsupported\n", pin);
}
}
BLYNK_WRITE_DEFAULT(){
int pin = request.pin;
switch(pin) {
case BUTTON: blynk_write_button(param); break;
case SLIDER: blynk_write_slider(param); break;
case TEXT_INPUT: blynk_write_text_input(param); break;
case NUMERIC_INPUT: blynk_write_numeric_input(param); break;
default:
Serial.printf("BLYNK_WRITE_DEFAULT: V%d Unsupported\n", pin);
}
}
void setup(void) {
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
while (!Blynk.connect());
}
void loop(void) {
Blynk.run();
}
Joe