In my Arduino project, I have three buttons, all connected with Virtual Pins (V1, V2, and V3). This is all working in the sense that I can turn the buttons on and off from within Cayenne and my code is working.
But I still have one problem. I have not seen a way using code in the Arduino sketch to change the state of any of the Virtual Pins and/or the buttons writing to them. What I need to do is turn off a button thatβs currently in the ON state using code.
My initial assumption about V1, V2, and V3 was that they were Boolean values - but that wasnβt correct. No matter what is going on within V1, the value of V1==1. Similarly V2==2 and V3==3. And thatβs always true, apparently.
What I need is to find out if itβs possible to have two-way communications between the code in the sketch and the buttons in the Cayenne interface.
Is there code I can write to turn off a button displayed in Cayenne?
Hereβs my code:
/*
Cayenne valves
*///#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneEthernet.h>int IRR = 0;
int RO = 0;
int LAKE = 0;
int IRR_LED1=2;
int RO_LED2=3;
int LAKE_LED3=4;// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token = βxxxxxxxxxxβ;void setup()
{
Serial.begin(9600);
Cayenne.begin(token);pinMode(IRR_LED1, OUTPUT);
pinMode(RO_LED2, OUTPUT);
pinMode(LAKE_LED3, OUTPUT);}
// VOID LOOP
void loop() {Cayenne.run();
}
CAYENNE_IN(V1)
{
int currentValue = getValue.asInt();
if (currentValue == 1)
{
IRR=1;
LAKE = 0;
digitalWrite(IRR_LED1, HIGH);
digitalWrite(LAKE_LED3, LOW);//
Serial.print(βIRR=β);
Serial.print(IRR);
Serial.print(" LAKE=β);
Serial.print(LAKE);
Serial.print(β V1=β);
Serial.print(V1);
Serial.print(β β);
}
else
{
IRR = 0;
digitalWrite(IRR_LED1, LOW);
Serial.print(βIRR=β);
Serial.print(IRR);
Serial.print(β LAKE=β);
Serial.print(LAKE);
Serial.print(β V1=β);
Serial.print(V1);
Serial.print(β ");
}
}CAYENNE_IN(V2)
{
int currentValue = getValue.asInt();
if (currentValue == 1)
{
RO=1;
LAKE = 0;
digitalWrite(RO_LED2, HIGH);
digitalWrite(LAKE_LED3, LOW);
Serial.print(βRO=β);
Serial.print(RO);
Serial.print(" LAKE=β);
Serial.print(LAKE);
Serial.print(β V2=β);
Serial.print(V2);
Serial.print(β β);
}
else
{
RO = 0;
digitalWrite(RO_LED2, LOW);
Serial.print(βRO=β);
Serial.print(RO);
Serial.print(β LAKE=β);
Serial.print(LAKE);
Serial.print(β V2=β);
Serial.print(V2);
Serial.print(β ");
}
}CAYENNE_IN(V3)
{
int currentValue = getValue.asInt();
if (currentValue == 1){
LAKE=1;
IRR = 0;
RO = 0;
digitalWrite(IRR_LED1, LOW);
digitalWrite(RO_LED2, LOW);
digitalWrite(LAKE_LED3, HIGH);
Serial.print(" LAKE=β);
Serial.print(LAKE);
Serial.print(βIRR=β);
Serial.print(IRR);
Serial.print(βRO=β);
Serial.print(RO);
Serial.print(β V3=β);
Serial.print(V3);
Serial.print(β β);
}
else
{
LAKE = 0;
digitalWrite(LAKE_LED3, LOW);
Serial.print(βLAKE=β);
Serial.print(LAKE);
Serial.print(β IRR=β);
Serial.print(IRR);
Serial.print(β RO=β);
Serial.print(RO);
Serial.print(β V3=β);
Serial.print(V3);
Serial.print(β ");
}
}