Register / Login  |  Desktop view  |  Jump to bottom of page

Any other library discussions » Switches

Author: homeplayer
23/02/2019 16:33:08
Good day to you all,

I hoop my request is a simple one.
I like to use the pcf8574 family (about 4 of them needed, in the current state of the house)
for inputs using the intPin. Don't want to waste energie and or processor resources on polling al the time,

Is it possible to have;
A Puls/Held --> Release switch - So a interrupt is detected, a small wait (20ms) if not held output a PULS - if held output HELD and after release a output RELEASE

I have read the hole library and all examples but could not find it and surely can't write it myself.
#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(); }


Last couple of days, I have bin surfing the net to find the code to make it work, on a RPI3 or arduino,

this library is getting so close to the code i am after, it will detect a second puls while a other pin is HELD perfect.


The output is now;
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

I like to daisy chain 3 or 4 pcf8574, and hope a for loop will do the rest, darn i wish i was a coder
I truly hope it's possible,

Kind regards

Spend a hour on it again after a relaxing sauna so new code up

Author: davetcc
25/02/2019 09:21:12
Apologies for the delay, there is a misconfiguration in the forum and it did not email me. I think see one error in there immediately.

Instead of initialising switches twice you create a MultiIoAbstraction that wraps up all of the ioFrom8574’s.

Take a look at the following:

https://github.com/davetcc/IoAbstraction/blob/master/examples/multiIoExample/multiIoExample.ino

Author: davetcc
25/02/2019 11:16:13
Also, In terms of interrupt polling. You’re already using interrupts for managing switches. So the only time it will poll is when a button is held down. Other than that it will wait for another interrupt.

The logic is

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.


Hope that is helpful
Dave

Author: homeplayer
25/11/2020 07:31:18
Not sure if it's oke to bump this old topic.

I found that "switches.onRelease(c1_btn02, c1_btn02Released);"
switches.onRelease
stops working in library 1.5 so it work till 1.4.11

Author: davetcc
25/11/2020 12:41:17
Thanks for letting me know, I'll try and take a look and post feedback here, I have an 8574 running in interrupt mode.

Author: davetcc
28/11/2020 09:41:48
I think we've found it, prior to 1.5 we used to initialise the switch if needed in the onRelease call, so there was no need to call addSwitch(), but this was inadvertently lost during a refactor, see: https://github.com/davetcc/IoAbstraction/issues/103




Register / Login  |  Desktop view  |  Jump to top of page