Giter Club home page Giter Club logo

Comments (3)

Devilcow avatar Devilcow commented on July 21, 2024 1

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.

LennartHennigs avatar LennartHennigs commented on July 21, 2024

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.

LennartHennigs avatar LennartHennigs commented on July 21, 2024

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)

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.