Any way to get a timed button?

I had a chance to test the pulse function of the Timer library, and it works as expected. Give it a try.

Every time you toggle the virtual button V0, the LED turns on, and then off after 1 second.

Craig

//#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space

#include <Timer.h> //https://github.com/JChristensen/Timer
#include <WiFi101.h> //https://github.com/arduino-libraries/WiFi101
#include <CayenneWiFi101.h> //https://github.com/myDevicesIoT/Cayenne-Arduino-Library

#define LED 2
Timer t;


// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "your_token"; 
// Your network name and password.
char ssid[] = "your_ssid";
char password[] = "your_pw";

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

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

CAYENNE_IN(V0)
{
  t.pulse(LED, 1000, 1); //pin, time(milliseconds), initial state
}
2 Likes