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
  Serial.println("Booting");
 
  pinMode(buttonPin, INPUT);
 
  //iot.setConfig("wname", WIFI_NAME);
  //iot.setConfig("wpass", WIFI_PASSWORD);
  // Print json config to serial
  iot.printConfig();
  // Initialize IoT library
  iot.setup();
}
 
void loop()
{
  // IoT behind the plan work, it should be periodically called
  iot.handle();
 
  // Askes in which state the button is, pressed, long pressed, double click, or released.
  button.poll();
 
  // If the button is long pressed, it publishes message “LongPressed”
  if (button.longPress()) {
    iot.log("LongPressed");
  }
 
  // If the button is double clicked, it publishes message “DoubleClick”
  if (button.doubleClick()) {
     iot.log("DoubleClick");
  }
 
  // If the button has been released, it publishes message “Released”
  if (button.released()) {
    iot.log("Released");
  }
 
  // If the button is pushed down, it publishes message “ButtonPushed”
  if (button.pushed()) {
    iot.log("ButtonPushed");
  }
 
  delay(3);
}
et/iot/examples/button.txt · Last modified: 2023/01/28 10:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0