Timed triggers


#1

Hi guys can someone tell me how to make an actuator to be “on” for a specified time? say have an LED turn on only for 10 seconds then turn off? do we have this option when using triggers? thanks.


#2

Using trigger this cannot be achieved. But this can be done by coding your device.


#3

Can u show me a sample sketch on how to accomplish this?Thanks in advance


#4

try this:

void setup() {
  pinMode(4, OUTPUT);
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID);
}
int x;
unsigned long lastMillis = 0;

void loop() {
  Cayenne.loop();
  if (x == 1)
  {
    if (millis() - lastMillis > 10000) {
      x = 0;
      Serial.println("led is off");
      digitalWrite(4, LOW);
      Cayenne.virtualWrite(1, 0);

    }
  }
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
  // Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
  Cayenne.virtualWrite(0, millis());
  // 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);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN(1)
{
  x = getValue.asInt();
  lastMillis = millis();
  Serial.println("led is on");
  digitalWrite(4, HIGH);
}

#5

thank u for your help. it worked!