A virtual button without a physical button

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

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

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

#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.

turn all to full brightness??

Yes
All 3 of them to full brightness

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);
}

1 Like

Alright Thank you sir!

You are very fast :slight_smile:

1 Like

@ognqn.chikov :wink:

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

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

Yeap

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);
}
}

Yes i did

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);
}

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

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);
}
}

3 Likes

try this code now

Nice it works now thank you so much.

2 Likes