[Logo] TCC discussion forum
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Top Downloads] Top Downloads   [Groups] Back to home page 
[Register] Register /  [Login] Login 


This forum is read only and new users cannot register, please ask all new questions either using GitHub discussions, or in Arduino forum tagging @davetcc.

Switches RSS feed
Forum Index » Any other library discussions
Author Message
homeplayer


Joined: Feb 22, 2019
Messages: 2
Offline
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
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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
homeplayer


Joined: Feb 22, 2019
Messages: 2
Offline
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
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
Thanks for letting me know, I'll try and take a look and post feedback here, I have an 8574 running in interrupt mode.
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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
 
Forum Index » Any other library discussions
Go to:   
Mobile view
Powered by JForum 2.7.0 © 2020 JForum Team • Maintained by Andowson Chang and Ulf Dittmer

This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK), and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.