Having trouble with coding. (Newbie)

Hi! (Sorry for bad english)
I started a project where by i have a RGB LED and i added 3 Luminosity widgets but i cant get them to work together.
When i entered the code they only work 1 by 1

This is the code. Please tell me what to add in so i can make virtual 1,2 and 3 work simultaneously
I plugged in my RGB LED to 3(Red),5(Blue),6(Green)

Steps:

  1. In the Cayenne Dashboard add a new Custom Widget, and select Slider.
  2. Select a virtual pin number.
  3. Set the slider widget min value to 0 and max value of 255.
  4. Set LED_VIRTUAL_PIN to the pin number you selected.
  5. Connect the LED’s legs to GND, and to a PWM pin (3, 5, 6, 9, 10, and 11 on most Arduino boards).
    Use a 1k resistor if possible.
    Schematic:
    [Ground] – [LED] – [1k-resistor] – [PWM Pin]
  6. Set LED_DIGITAL_PIN to the PWM pin number you selected.
  7. Set the token variable to match the Arduino token from the Dashboard.
  8. Compile and upload this sketch.
  9. Once the Arduino connects to the Dashboard you can use the slider to change LED brightness.
    */

#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_PIN 3
#define LED_DIGITAL_PIN 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_PIN)
{
// get value sent from dashboard
int currentValue = getValue.asInt(); // 0 to 255
analogWrite(LED_DIGITAL_PIN, currentValue); // analogWrite accepts a value from 0 to 255
}

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

@freddyisdabest2 you have your code only written for one virtual pin and led pin.
you have to write for all three virtual and led pins.
#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 currentValue2 = getValue.asInt(); // 0 to 255
analogWrite(LED_DIGITAL_PIN2, currentValue2); // analogWrite accepts a value from 0 to 255
}
CAYENNE_IN(LED_VIRTUAL_PIN1)
{
// get value sent from dashboard
int currentValue3 = getValue.asInt(); // 0 to 255
analogWrite(LED_DIGITAL_PIN3, currentValue3); // analogWrite accepts a value from 0 to 255
}

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

2 Likes

Hi Thanks for replying!
I will try it tomorrow and will tell you how everything goes

2 Likes