Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot:examples:button [2020/07/20 11:26] – external edit 127.0.0.1en:iot:examples:button [Unknown date] (current) – external edit (Unknown date) 127.0.0.1
Line 5: Line 5:
 The code above will send message to log if button pressed The code above will send message to log if button pressed
  
-<code>lib_deps = ITTIoT@1.0.52947</code>+<code>lib_deps = ITTIoT, blackketter/Switch</code>
  
 <code c> <code c>
Line 17: Line 17:
  */  */
  
 +// Includes global variables and librarys that the Buzzer uses
 #include <Arduino.h> #include <Arduino.h>
 #include <ittiot.h> #include <ittiot.h>
 #include <Switch.h> #include <Switch.h>
  
 +#define WIFI_NAME "name"
 +#define WIFI_PASSWORD "password"
  
-const byte buttonPin = D3;+const byte buttonPin = D3; // TO which pin the button has been assigned
 int i; int i;
  
 Switch button = Switch(buttonPin); Switch button = Switch(buttonPin);
  
-void iot_received(String topic, String msg) +void iot_received(String topic, String msg) {}
-{ +
-  Serial.print("MSG FROM USER callback, topic: "); +
-  Serial.print(topic); +
-  Serial.print(" payload: "); +
-  Serial.println(msg); +
-  +
-}+
  
 // Function started after the connection to the server is established. // Function started after the connection to the server is established.
Line 40: Line 36:
 { {
   Serial.println("MQTT connected callback");   Serial.println("MQTT connected callback");
-  // Subscribe to the topic "button" 
-  iot.subscribe("button"); 
   iot.log("IoT Button example!");   iot.log("IoT Button example!");
 } }
Line 47: Line 41:
 void setup() void setup()
 { {
-  Serial.begin(115200);+  Serial.begin(115200); // setting up serial connection parameter
   Serial.println("Booting");   Serial.println("Booting");
  
   pinMode(buttonPin, INPUT);   pinMode(buttonPin, INPUT);
 +
 +  //iot.setConfig("wname", WIFI_NAME);
 +  //iot.setConfig("wpass", WIFI_PASSWORD);
   // Print json config to serial   // Print json config to serial
   iot.printConfig();   iot.printConfig();
   // Initialize IoT library   // Initialize IoT library
   iot.setup();   iot.setup();
-  // Initialize relay pin 
- 
 } }
  
Line 63: Line 58:
   // IoT behind the plan work, it should be periodically called   // IoT behind the plan work, it should be periodically called
   iot.handle();   iot.handle();
-  delay(200);+ 
 +  // Askes in which state the button is, pressed, long pressed, double click, or released.
   button.poll();   button.poll();
  
 +  // If the button is long pressed, it publishes message “LongPressed”
   if (button.longPress()) {   if (button.longPress()) {
     iot.log("LongPressed");     iot.log("LongPressed");
   }   }
  
 +  // If the button is double clicked, it publishes message “DoubleClick”
   if (button.doubleClick()) {   if (button.doubleClick()) {
      iot.log("DoubleClick");      iot.log("DoubleClick");
   }   }
-   
  
 +  // If the button has been released, it publishes message “Released”
   if (button.released()) {   if (button.released()) {
-    iot.log("released\n"); +    iot.log("Released");
-+
- +
- if (button.pushed()) { +
-    iot.log("Button Pushed");+
   }   }
  
 +  // If the button is pushed down, it publishes message “ButtonPushed”
 +  if (button.pushed()) {
 +    iot.log("ButtonPushed");
 +  }
 +  
 +  delay(3);
 } }
  
 </code> </code>
en/iot/examples/button.1595244384.txt.gz · Last modified: 2020/07/20 09: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