Hello
have a question how does the Segmented Switch how does it work with a switch because of the commands
With default setting, V0 will get ether a 1 or a 2 depending on the button pressed.
ok Do you have a code example for me that looks like I need to write that at blynk
Yes, this is for virtual pins… and the base code is the same as reading the vPin on every other Widget.
http://docs.blynk.cc/#blynk-firmware-virtual-pins-control-blynk_writevpin
And with this segmented switch, you can go up to 5 options, so Switch Case code might work best.
https://www.arduino.cc/reference/en/language/structure/control-structure/switchcase/
BLYNK_WRITE(vPin) {
switch (param.asInt())
{
case 1: { // Item 1
// Do something
break;
}
case 2: { // Item 2
// Do something
break;
}
case 3: { // Item 3
// Do something
break;
}
case 4: { // Item 4
// Do something
break;
}
case 5: { // Item 5
// Do something
break;
}
}
}
ok ok thank you now i understood it thank you
hello guys, I searched around the forum for a complete sketch to understand how to use the segmented switch, but nothing concrete. now I tried to make one myself, based on what I had and it does not work. now I publish my sketch and if anyone can help me I would be grateful.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "ab8d921c32axxxxxxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "NULL";
char pass[] = "XXXXXXXXXX";
// Select your pin with physical button
const int d6 = D6; // IL primo valore d5 è il nome il secondo e il reale PIN
const int d5 = D5;
WidgetLCD lcd(V3);
WidgetLCD lcd2(V6);
BlynkTimer timer;
// V1 LED Widget represents the physical button state
boolean sensore1 = false;
boolean sensore2 = false;
BLYNK_WRITE(V20) {
switch (param.asInt())
{
case 1: {
void SensorePorta()
{
// Read button
boolean isPressed = (digitalRead(d6) == LOW);
// If state has changed...
if (isPressed != sensore1) {
if (isPressed) {
lcd.print(3, 0, "PORTA"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd.print(4, 1, "CHIUSA");
} else {
lcd.print(3, 0, "PORTA"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd.print(4, 1, "APERTA");
Blynk.notify("PORTA APERTA");
}
sensore1 = isPressed;}
break;
}
case 2: {
void SensorePorta()
{
// Read button
boolean isPressed = (digitalRead(d6) == LOW);
// If state has changed...
if (isPressed != sensore1) {
if (isPressed) {
lcd.print(3, 0, "PORTA"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd.print(4, 1, "CHIUSA");
} else {
lcd.print(3, 0, "PORTA"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd.print(4, 1, "APERTA");
}
sensore1 = isPressed;
}
}
break;
}
}
}
void SensoreCitofono()
{
// Read button
boolean isPressed = (digitalRead(d5) == LOW);
if (isPressed != sensore2) {
if (isPressed) {
lcd2.clear();
lcd2.print(2, 0, "HANNO SUONATO"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd2.print(2, 1, "ALLA PORTA");
Blynk.notify("HANNO SUONATO ALLA PORTA");
delay(10000);
} else {
lcd2.clear();
lcd2.print(2, 0, "CAMPANELLO"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd2.print(2, 1, "LIBERO");
}
sensore2 = isPressed;
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// Setup physical button pin (active low)
pinMode(d6, INPUT_PULLUP);
pinMode(d5, INPUT_PULLUP);
timer.setInterval(100L, SensorePorta); //buttonLedWidget
timer.setInterval(100L, SensoreCitofono);
// IMPOSTAZIONE NOTIFICA DISPOSITIVO ONLINE
//*****************************************
while (Blynk.connect() == false) {}
Blynk.notify("SENSORE PORTA-CAMPANELLO--ONLINE--");
}
void loop()
{
Blynk.run();
timer.run();
}
it’s wrong…
my segmented switch for a menu
BLYNK_WRITE(V11)// menu segmented switch
{
switch (param.asInt()) {
case 1: { // Item 1
Menu = 1;
break;
}
case 2: { // Item 2
Menu = 2;
break;
}
case 3: { // Item 3
Menu = 3;
break;
}
case 4: { // Item 4
Menu = 4;
break;
}
}
}
yes, bracket missing
lcd.print(3, 0, "PORTA"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd.print(4, 1, "APERTA");
}
sensore1 = isPressed;
}
}
break;
}
}
}
} //<<-------------
so inserting the parenthesis works?
I don’t know, but the bracket is missing that is sure
and I m not sure you understand switch case
BLYNK_WRITE(V20) {
switch (param.asInt())
{
case 1: {
void SensorePorta() //<------------------------- why?
and case 1 is same than case 2
I’ll explain, this is a sketch to see if the front door is open or closed. in the first case it tells me if the door is open or closed but I do not get the notification because it is disabled, in the second case I must notify me that the door has been opened if the sensors detect it. I do not know if you can understand why I’m helping google translator. thank you for your time
and your scketch run or you get issues ?
What is the difference between the Menu widget and this Segmented Switch? They appear to do the same thing.
Segmented Switch Widget is a simpler multi-button control. The Menu Widget is… well, a full menu … more options, but more steps to pick them.
the base of my sketch works, but when I want to add the change with the addition of the segmented switch it does not work anymore because I think it’s wrong
yes because you have your void into the two switch case.
give me some advice on how I can correctly modify this sketch
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "ab8d921c32axxxxxxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "NULL";
char pass[] = "XXXXXXXXXX";
// Select your pin with physical button
const int d6 = D6; // IL primo valore d5 è il nome il secondo e il reale PIN
const int d5 = D5;
WidgetLCD lcd(V3);
WidgetLCD lcd2(V6);
BlynkTimer timer;
// V1 LED Widget represents the physical button state
boolean sensore1 = false;
boolean sensore2 = false;
BLYNK_WRITE(V20) {
switch (param.asInt())
{
case 1: {
SensorePorta();
break;
}
case 2: {
SensorePorta();
break;
}
}
}
void SensorePorta(){
// Read button
boolean isPressed = (digitalRead(d6) == LOW);
// If state has changed...
if (isPressed != sensore1) {
if (isPressed) {
lcd.print(3, 0, "PORTA"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd.print(4, 1, "CHIUSA");
} else {
lcd.print(3, 0, "PORTA"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd.print(4, 1, "APERTA");
Blynk.notify("PORTA APERTA");
}
sensore1 = isPressed;
}
}
void SensoreCitofono()
{
// Read button
boolean isPressed = (digitalRead(d5) == LOW);
if (isPressed != sensore2) {
if (isPressed) {
lcd2.clear();
lcd2.print(2, 0, "HANNO SUONATO"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd2.print(2, 1, "ALLA PORTA");
Blynk.notify("HANNO SUONATO ALLA PORTA");
delay(10000);
} else {
lcd2.clear();
lcd2.print(2, 0, "CAMPANELLO"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd2.print(2, 1, "LIBERO");
}
sensore2 = isPressed;
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// Setup physical button pin (active low)
pinMode(d6, INPUT_PULLUP);
pinMode(d5, INPUT_PULLUP);
timer.setInterval(100L, SensorePorta); //buttonLedWidget
timer.setInterval(100L, SensoreCitofono);
// IMPOSTAZIONE NOTIFICA DISPOSITIVO ONLINE
//*****************************************
while (Blynk.connect() == false) {}
Blynk.notify("SENSORE PORTA-CAMPANELLO--ONLINE--");
}
void loop()
{
Blynk.run();
timer.run();
}