A virtual button without a physical button


#1

Im trying to make my RGB LED Sliders(RED GREEN AND BLUE) all turn on at the same time and turn off at the same time without a physical button. Is this possible i’ve tried setting triggers but it doesn’t work. Please help


#2

Hello Sir,
Can you give more information about the board that you use and also the configuration?


#3

@freddyisdabest2 can you provide more detail on what you want to achieve and what is the problem with triggers?


#4

#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space

// If you’re not using the Ethernet W5100 shield, change this to match your connection type. See Communications examples.
#include <CayenneEthernet.h>

#define LED_VIRTUAL_PIN1 1
#define LED_DIGITAL_PIN1 3

#define LED_VIRTUAL_PIN2 2
#define LED_DIGITAL_PIN2 5

#define LED_VIRTUAL_PIN3 3
#define LED_DIGITAL_PIN3 6

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = “AuthenticationToken”;

void setup()
{
Serial.begin(9600);
Cayenne.begin(token);
}

CAYENNE_IN(LED_VIRTUAL_PIN1)
{
// get value sent from dashboard
int currentValue1 = getValue.asInt(); // 0 to 255
analogWrite(LED_DIGITAL_PIN1, currentValue1); // analogWrite accepts a value from 0 to 255
}

CAYENNE_IN(LED_VIRTUAL_PIN2)
{
// get value sent from dashboard
int currentValue1 = getValue.asInt(); // 0 to 255
analogWrite(LED_DIGITAL_PIN2, currentValue1); // analogWrite accepts a value from 0 to 255
}
CAYENNE_IN(LED_VIRTUAL_PIN3)
{
// get value sent from dashboard
int currentValue1 = getValue.asInt(); // 0 to 255
analogWrite(LED_DIGITAL_PIN3, currentValue1); // analogWrite accepts a value from 0 to 255
}

void loop()
{
Cayenne.run();
}

This is my code.

Im trying to turn on all of the sliders by using a custom widget button. But i dont know how to.


#5

turn all to full brightness??


#6

Yes
All 3 of them to full brightness


#7

this can be done without using triggers but by programming.
set your custom widget button to virtual pin 4.
CAYENNE_IN(V4)
{
// get value sent from dashboard
int currentValue = getValue.asInt();
if (currentValue =1)
{
digitalWrite(LED_DIGITAL_PIN1, HIGH);
digitalWrite(LED_DIGITAL_PIN2, HIGH);
digitalWrite(LED_DIGITAL_PIN3, HIGH);
}
else
{
digitalWrite(LED_DIGITAL_PIN1, LOW);
digitalWrite(LED_DIGITAL_PIN2, LOW);
digitalWrite(LED_DIGITAL_PIN3, LOW);
}


#8

Alright Thank you sir!


#9

You are very fast :slight_smile:


#10

@ognqn.chikov :wink:


#11

Uhh slight problem the light just stays on and it doesn’t turn off :frowning:


#12

even when you deselect(press again) the custom widget button??


#13

Yeap


#14

did you add the missing } at last in the code i gave??
CAYENNE_IN(V4)
{
// get value sent from dashboard
int currentValue = getValue.asInt();
if (currentValue =1)
{
digitalWrite(LED_DIGITAL_PIN1, HIGH);
digitalWrite(LED_DIGITAL_PIN2, HIGH);
digitalWrite(LED_DIGITAL_PIN3, HIGH);
}
else
{
digitalWrite(LED_DIGITAL_PIN1, LOW);
digitalWrite(LED_DIGITAL_PIN2, LOW);
digitalWrite(LED_DIGITAL_PIN3, LOW);
}
}


#15

Yes i did


#16

use serial.println to check if you are receiving 1 or 0.
CAYENNE_IN(V4)
{
// get value sent from dashboard
int currentValue = getValue.asInt();
if (currentValue =1)
{
Serial.println(“on”);
digitalWrite(LED_DIGITAL_PIN1, HIGH);
digitalWrite(LED_DIGITAL_PIN2, HIGH);
digitalWrite(LED_DIGITAL_PIN3, HIGH);
}
else
{
Serial.println(“off”);
digitalWrite(LED_DIGITAL_PIN1, LOW);
digitalWrite(LED_DIGITAL_PIN2, LOW);
digitalWrite(LED_DIGITAL_PIN3, LOW);
}


#17

i only receive on and not off even though i clicked the button off it still says on on the serial monitor.

[5001] Connecting to arduino.mydevices.com:8442
[5754] Ready (ping: 265ms).
on
on
on


#18

CAYENNE_IN(V4)
{
// get value sent from dashboard
int currentValue = getValue.asInt();
if (currentValue ==1)
{
Serial.println(“on”);
digitalWrite(LED_DIGITAL_PIN1, HIGH);
digitalWrite(LED_DIGITAL_PIN2, HIGH);
digitalWrite(LED_DIGITAL_PIN3, HIGH);
}
else
{
Serial.println(“off”);
digitalWrite(LED_DIGITAL_PIN1, LOW);
digitalWrite(LED_DIGITAL_PIN2, LOW);
digitalWrite(LED_DIGITAL_PIN3, LOW);
}
}


#19

try this code now


#20

Nice it works now thank you so much.