Hi Cayenne. I am working on a project where the cayenne widgets will serve as buttons of a keypad and when the correct four (out of the eight) widgets are selected (regardless of the order those four widgets are pressed), it will light up an LED.
Here is the code:
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";
#define VIRTUAL_CHANNEL_2 2
#define ACTUATOR_PIN_2 2
#define VIRTUAL_CHANNEL_3 3
#define ACTUATOR_PIN_3 3
#define VIRTUAL_CHANNEL_4 4
#define ACTUATOR_PIN_4 4
#define VIRTUAL_CHANNEL_5 5
#define ACTUATOR_PIN_5 5
#define VIRTUAL_CHANNEL_6 6
#define ACTUATOR_PIN_6 6
#define VIRTUAL_CHANNEL_7 7
#define ACTUATOR_PIN_7 7
#define VIRTUAL_CHANNEL_8 8
#define ACTUATOR_PIN_8 8
#define VIRTUAL_CHANNEL_9 9
#define ACTUATOR_PIN_9 9
void setup()
{
Serial.begin(9600);
pinMode(ACTUATOR_PIN_2, OUTPUT);
pinMode(ACTUATOR_PIN_3, OUTPUT);
pinMode(ACTUATOR_PIN_4, OUTPUT);
pinMode(ACTUATOR_PIN_5, OUTPUT);
pinMode(ACTUATOR_PIN_6, OUTPUT);
pinMode(ACTUATOR_PIN_7, OUTPUT);
pinMode(ACTUATOR_PIN_8, OUTPUT);
pinMode(ACTUATOR_PIN_9, OUTPUT);
Cayenne.begin(username, password, clientID);
}
void loop()
{
Cayenne.loop();
if (digitalRead(2) == HIGH &&
digitalRead(3) == HIGH &&
digitalRead(4) == HIGH &&
digitalRead(5) == HIGH &&
digitalRead(6) == LOW &&
digitalRead(7) == LOW &&
digitalRead(8) == LOW &&
digitalRead(9) == LOW)
{
digitalWrite(10,HIGH);
}
}
// This function is for button 2.
CAYENNE_IN(2)
{
int value = getValue.asInt();
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_2, ACTUATOR_PIN_2, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN_2, value);
}
// This function is for button 3.
CAYENNE_IN(3)
{
int value = getValue.asInt();
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_3, ACTUATOR_PIN_3, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN_3, value);
}
// This function is for button 4.
CAYENNE_IN(4)
{
int value = getValue.asInt();
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_4, ACTUATOR_PIN_4, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN_4, value);
}
// This function is for button 5.
CAYENNE_IN(5)
{
int value = getValue.asInt();
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_5, ACTUATOR_PIN_5, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN_5, value);
}
// This function is for button 6
CAYENNE_IN(6)
{
int value = getValue.asInt();
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_6, ACTUATOR_PIN_6, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN_6, value);
}
// This function is for button 7.
CAYENNE_IN(7)
{
int value = getValue.asInt();
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_7, ACTUATOR_PIN_7, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN_7, value);
}
// This function is for button 8.
CAYENNE_IN(8)
{
int value = getValue.asInt();
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_8, ACTUATOR_PIN_8, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN_8, value);
}
// This function is for button 9.
CAYENNE_IN(9)
{
int value = getValue.asInt();
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_9, ACTUATOR_PIN_9, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN_9, value);
}
Can u help me figure out what’s wrong with my code? Appreciate your help always.