Nupu näidis

Vajaminevad teegid:

lib_deps = ITTIoT, blackketter/Switch

Näidiskood saadab sõnumi logisse kui nuppu vajutatakse:

 * IoT Button example
 * This example subscribe to the "button" topic. When a message received, then it
 * will show the message
 * Created 21 Febuary 2018 by Mallor Kingsepp
// Includes global variables and librarys that the Buzzer uses
#include <Arduino.h>
#include <ittiot.h>
#include <Switch.h>
#define WIFI_NAME "name"
#define WIFI_PASSWORD "password"
const byte buttonPin = D3; // TO which pin the button has been assigned
int i;
Switch button = Switch(buttonPin);
void iot_received(String topic, String msg) {}
// Function started after the connection to the server is established.
void iot_connected()
  Serial.println("MQTT connected callback");
  iot.log("IoT Button example!");
void setup()
  Serial.begin(115200); // setting up serial connection parameter
  pinMode(buttonPin, INPUT);
  //iot.setConfig("wname", WIFI_NAME);
  //iot.setConfig("wpass", WIFI_PASSWORD);
  // Print json config to serial
  // Initialize IoT library
void loop()
  // IoT behind the plan work, it should be periodically called
  // Askes in which state the button is, pressed, long pressed, double click, or released.
  // If the button is long pressed, it publishes message “LongPressed”
  if (button.longPress()) {
  // If the button is double clicked, it publishes message “DoubleClick”
  if (button.doubleClick()) {
  // If the button has been released, it publishes message “Released”
  if (button.released()) {
  // If the button is pushed down, it publishes message “ButtonPushed”
  if (button.pushed()) {
et/iot/examples/button.txt · Last modified: 2023/01/28 10:00 (external edit)
CC Attribution-Share Alike 4.0 International Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0