Code Monkey home page Code Monkey logo

simplebutton's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simplebutton's Issues

missing INPUT_PULLDOWN

hi, in case of button to be active HIGH, there should be proper way of pulling down the pin
there is nothing I could find like this in your code so I had to add it manually
maybe it would be good to have such functionality (when inverted make it pull down)?

or maybe I am not doing it properly?

papio@MBP16papio SimpleButton % grep -R PULL * examples/PullupButton/PullupButton.ino: // ButtonPullup will do "pinMode(12, INPUT_PULLUP)" isntead of "pinMode(12, INPUT)". src/Buttons/PS2Gamepad.cpp: pinMode(dataPin, INPUT_PULLUP); src/Buttons/ButtonPullup.cpp: pinMode(button_pin, INPUT_PULLUP); src/libs/MCP23017.cpp: setPinMode(pin, pullup ? INPUT_PULLUP : INPUT); src/libs/MCP23017.cpp: bool input = (mode == INPUT || mode == INPUT_PULLUP); src/libs/MCP23017.cpp: bool pullup = (mode == INPUT_PULLUP); src/libs/MCP23017.cpp: if (pullup) return INPUT_PULLUP; papio@MBP16papio SimpleButton %

Use GPIO interrupt instead of polling GPIO

Would it improve performance to not read the GPIO by polling it in the arduino loop, but to have an interrupt attached to the button, and read it after the interrupt fires?

How could that be done?

Interference with PubSubClient

Hello. I am using SimpleButton liblary in my project and it is working verry well.
I use ESP8266 and buttons connected to GPIO expander - MCP23017.

The issue i have is when i try to use PubSubClient and SimpleButton liblary together.

My code:

`#include <Arduino.h>
#include <ESP8266WiFi.h> //WIFI liblary

#include <PubSubClient.h> //MQTT liblary
WiFiClient espClient;
PubSubClient client(espClient);
void callback(char* topic, byte* payload, unsigned int length);

const char* ssid = "xxxx"; // Enter your WiFi name
const char* password = "xxxxx."; // Enter WiFi password
const char* mqttServer = "xxxxx";
const int mqttPort = 1883;
const char* mqttUser = "xxxxx";
const char* mqttPassword = "xxxxx";
const char* clientID = "ESP8266";

#include <SimpleButton.h> //button listener liblary
using namespace simplebutton;
//Initialize buttons:
Button* Button1 = NULL;

void setup() {
// put your setup code here, to run once:
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println();

pinMode(D3, OUTPUT);
digitalWrite(D3, LOW);

//Connect to WIFI network:
WiFi.begin(ssid, password);

Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println();

Serial.print("Connected, IP address: ");
Serial.println(WiFi.localIP());

//MQTT broker:
client.setServer(mqttServer, mqttPort); // set server settings for connection
client.setCallback(callback); // for incoming messages

//Connect to MQTT broker:
while (!client.connected()) {
Serial.println("Connecting to MQTT...");

if (client.connect(clientID, mqttUser, mqttPassword )) {

  Serial.println("connected");  

} else {

  Serial.print("failed with state ");
  Serial.print(client.state());
  delay(2000);

}

}

client.subscribe("Subscribe1");

Wire.begin(D2, D1); // begin i2c bus on SDA=D2 and SCL=D1

//Configure the input MCP23017 modules:
GPIOExpander* mcpDI = new MCP23017(0x20);

//Make sure cnnection is sucessfull:

if(mcpDI->connected()){Serial.println("mcpDO connected"); }
//Define connection between output module I/Os and buttons A0=0, A1=1, ......, B0=8, ..., B8=15
Button1 = new ButtonPullupGPIOExpander(mcpDI, 0);

}

void OutputAction(int o){
switch (o) {
case 0:
digitalWrite(D3, LOW);
client.publish("Publish1", "0");
break;
case 1:
digitalWrite(D3, HIGH);
client.publish("Publish1", "1");
break;
}
}

void callback(char* topic, byte* payload, unsigned int length) {

Serial.print("Message arrived in topic: ");
Serial.println(topic);

Serial.print("Message:");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}

String thisTopic = topic;
byte thisPayload = *payload;
int ukaz = ((int)thisPayload-48);

if(thisTopic.equals("Subscribe1")){
switch(ukaz){
case 0:
OutputAction(0);
break;
case 1:
OutputAction(1);
break;
}
}
}

void loop() {
// put your main code here, to run repeatedly:
client.loop();

if (!client.connected())
{
Serial.println("MQTT not connected");
client.connect(clientID, mqttUser, mqttPassword );
client.subscribe("Subscribe1");
}

Button1->update();

if(Button1->clicked()){ OutputAction(1); }
if(Button1->holding()){ OutputAction(0); }

}`

The issue i am having is that MQTT gets disconnected when i use Button1->update(); and it never connects again.
If i comment out the Button1->update(); it works well. But of course the button does not respond.

I was hoping someone can share some light on this issue.
I do not have enough experience to find a solution.

Error on Compiling at the first run

At the first compiling i recive this error:

In file included from C:\Users\Fabio >Capo\Documents\Arduino\libraries\SimpleButton\src/Buttons/Button.h:5:0,

             from C:\Users\Fabio Capo\Documents\Arduino\libraries\SimpleButton\src/SimpleButton.h:4,

             from C:\Users\Fabio Capo\Documents\Arduino\libraries\SimpleButton\examples\Button\Button.ino:1:

C:\Users\Fabio Capo\Documents\Arduino\libraries\SimpleButton\src/Events/Event.h:5:22: fatal error: >functional: No such file or directory
compilation terminated.

This happen on example also!

Any ideas?

events clicked and holding do interfere

If i use events clicked and holding on the same button, they interfere: when holding the button, this generates the holding event, but also an unsolicited clicked event.

include functional

hello i 've tried your library (on an arduino nano) but for the rotary encoder example it bring an error "include functional" ... any idea?
thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.