Comments (3)
Very cool, thanks!
I have been reworking my code some. I've basically adopted a MessagePump
model as you suggested. My click handler toggles existing flags, so that if the program is in the set rpms state state & SETRPM == SETRPM
it flips that bit for me state ^= SETRPM
.
I then use long, double, and tripple clicks to set conditions for RUNNING|SETRPM|SETRUNTIME
respectively.
Of course now I am running into some different issues with running on an UNO, mainly the lack of pushing functions to separate threads (I'm looking into some libs like SoftTimer
and other protothreading methods).
My loop currently is just
void loop()
{
button.loop();
pot_val = analogRead(POT_PIN);
MessagePump(state);
}
My biggest problem at this point is that I'm used to writing code with the concern focused on functionality and richness, not so much on small binaries. There's no reason that a simple rock tumbler should need more than a 328, but god knows life would be so much easier if I were to write it for a 2560 LOL
Thanks for the lib! Makes life much easier!
Cheers!
from button2.
Hey cow,
well, the concept I use with the callback functions is very similar to the idea of "real" interrupts, as the functions are called as soon as a certain click is detected.
To your question, I'd use the call back functions to set variable to keep track of the state of your app.
In your loop()
function I'd check those and do the handling there (e.g. stop the loop, display information...)
This keeps the call backs lean and the handling of things is done in one place.
Just introduce a couple of global variables to keep track of "am I running", "what should I display?" and you should be fine.
(And since you did not post your loop()
, remember to add a button.loop()
there.)
Cheers
l.
from button2.
Well, if size is a now a "problem" get an ESP8266 or 32 (maybe a Wemos D1 Mini). Cheap, more memory and Wi-Fi. Then you "solve" the code bumming problem by getting something more powerful but cheap... 😀
Cheers.
from button2.
Related Issues (20)
- .pio/libdeps/seeed_xiao_esp32c3/Button2/src/Button2.cpp:186:20: error: 'touchRead' was not declared in this scope HOT 2
- detection of long presses does not work properly inside of an interupt timer HOT 2
- Interrupt wdt timeout on CPU1 HOT 2
- button.isPressed(); seems to stay latched. HOT 1
- Long press is not reported in polling mode HOT 1
- Change std::functional guards from platform-based to language version-based HOT 1
- multiple ESP32CapacitiveTouch.ino HOT 1
- 2.3.0 breaks at least on RP2040 with type errors HOT 3
- 2.3.x breaks default implementation? HOT 4
- Advices for implementing a speed-sensitive button-press control HOT 1
- setStateHandler Functions HOT 1
- Multiplexed buttons support HOT 1
- Use hall sensor instead button HOT 1
- 2.3.x does not compile on Arduino Uno R4 HOT 3
- Watchdog timer triggered on both ESP32 Capacitive Touch examples HOT 1
- virtual button init callback HOT 1
- another i2c PE button question HOT 8
- update constants in examples
- Problem with longpress behavior HOT 3
- [question] Is it compatible with all microcontrollers having an Arduino framework implementation? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from button2.