you have to select different channel for each button and then add code to read each button:
select channel 1 for led 4 button and channel 2 for led 5 button.
CAYENNE_IN(1) // Get current value of led 4 button
{
int x = getValue.asInt();
digitalWrite(led_4_pin, x);
}
CAYENNE_IN(2) // Get current value of led 5 button
{
int x1 = getValue.asInt();
digitalWrite(led_5_pin, x1);
}
// This example shows how to connect to Cayenne using an Ethernet W5100 shield and send/receive sample data.
//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTEthernet.h>
#define led_4_pin 6
#define led_5_pin 7
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";
unsigned long lastMillis = 0;
void setup() {
Serial.begin(9600);
pinMode(led_4_pin, OUTPUT);
pinMode(led_5_pin, OUTPUT);
Cayenne.begin(username, password, clientID);
}
void loop() {
Cayenne.loop();
//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
if (millis() - lastMillis > 10000) {
lastMillis = millis();
//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
Cayenne.virtualWrite(0, lastMillis);
//Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}
}
CAYENNE_IN(1) // Get current value of led 4 button
{
int x = getValue.asInt();
digitalWrite(led_4_pin, x);
}
CAYENNE_IN(2) // Get current value of led 5 button
{
int x1 = getValue.asInt();
digitalWrite(led_5_pin, x1);
}