Register / Login | Desktop view |
#include<IoAbstraction.h>
#include<IoAbstractionWire.h>
const int c1_btn01 = 0;
const int c1_btn02 = 1;
const int c2_btn01 = 2;
const int c2_btn02 = 3;
void c1_btn02Clicked(uint8_t pin, bool heldDown) {
Serial.print(c1_btn02);
Serial.println(heldDown ? " MQTT send presed" : "");
}
void c1_btn02Released(uint8_t pin, bool heldDown) {
Serial.print(c1_btn02);
Serial.println(heldDown ? " MQTT send Released" : " MQTT send Puls");
}
void setup() {
// Before doing anything else, we must initialise the wire and serial libraries, as we are using both.
Serial.begin(9600);
Wire.begin();
// First we set up the switches library, giving it the task manager and tell it where the pins are located
// We could also of chosen IO through an i2c device that supports interrupts.
// the second parameter is a flag to use pull up switching, (true is pull up).
// switches.initialiseInterrupt(ioFrom8574(0x20, 2), true);
switches.initialiseInterrupt(ioFrom8574(0x38, 2), true);
// now we add the switches, we dont want the spinwheel button to repeat, so leave off the last parameter
// which is the repeat interval (millis / 20 basically) Repeat button does repeat as we can see.
switches.addSwitch(c1_btn02, c1_btn02Clicked);
switches.onRelease(c1_btn02, c1_btn02Released);
}
void loop() {
taskManager.runLoop(); }
1
1 MQTT send Puls
1
1 MQTT send presed
1 MQTT send Released
1
1 MQTT send presed
1 MQTT send Released
1
1 MQTT send Puls
Wait for an interrupt
de-bounce
If pressed then Start timing loop
Check and fire any repeat keys
Keep in loop until no longer pressed.
switches.onRelease
stops working in library 1.5 so it work till 1.4.11