SimpleCloudButtonYun.ino 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. ArduinoCloudThing Cloud Button
  3. Simple cloud button example that use the BridgeSSL client and display on the
  4. arduino cloud dashboard the value of button.
  5. Arduino Cloud -> https://cloud.arduino.cc/cloud
  6. IMPORTANT: in order to establish the tls connection and use the BridgeSSL
  7. the yun firmware version should be >=1.6.2, look at
  8. https://www.arduino.cc/en/Tutorial/YunSysupgrade
  9. created May 2016
  10. by Gilberto Conti and Sandeep Mistry
  11. */
  12. #include <ArduinoCloud.h>
  13. #include <BridgeSSLClient.h>
  14. BridgeSSLClient sslClient;
  15. // build a new thing "cloudObject"
  16. ArduinoCloudThing cloudObject;
  17. // Arduino Cloud settings and credentials
  18. const char userName[] = "";
  19. const char thingName[] = "";
  20. const char thingId[] = "";
  21. const char thingPsw[] = "";
  22. const int buttonPin = 6;
  23. void setup() {
  24. SerialUSB.begin(9600);
  25. // configure the button pin as input
  26. pinMode(buttonPin, INPUT);
  27. // start the bridge
  28. Bridge.begin();
  29. // setup the "cloudObject"
  30. cloudObject.enableDebug(); // eneble the serial debug output
  31. cloudObject.begin(thingName, userName, thingId, thingPsw, sslClient);
  32. // define the properties
  33. cloudObject.addProperty("position", STATUS , R);
  34. }
  35. void loop() {
  36. // subscribes to RW properties and look at the connections status
  37. cloudObject.poll();
  38. // read the button
  39. if (digitalRead(buttonPin) == HIGH) {
  40. // button is pressed, write position as "on"
  41. cloudObject.writeProperty("position", "on");
  42. } else {
  43. // button is released, write position as "off"
  44. cloudObject.writeProperty("position", "off");
  45. }
  46. delay(1000);
  47. }