====== Button example ====== {{:en:iot:examples:buttonshield.png?200|}} The code above will send message to log if button pressed lib_deps = ITTIoT, blackketter/Switch /* * 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 #include #include #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); }