Go Down

Topic: standard shipped libs (Read 694 times) previous topic - next topic

drjiohnsmith

Just a thought,

I've been helping some people come up to speed on arduino,
   they are all working on projects that need to take in controls form buttons an keypads,

and they have all come up with different libs from the arduino sites.
   I did not realise there were so many different libs that are designed to cope with buttons.

Suggestion , I'd guess that a large majority of arduino projects take in a sensor or two, that could be a button class,

I don't suppose that we could have one standard library to handle buttons effectively ?
   how about one that can handle all sorts of button sensors, key pads scanned and none scanned.

As I say, i know there are different libs for all these, I think my students have found every combination possible, which in some ways is good, it just makes using and debugging much harder than it should be for a simple function like reading a switch.


 

MichaelMeissner

#1
Aug 07, 2012, 03:46 pm Last Edit: Aug 07, 2012, 03:55 pm by MichaelMeissner Reason: 1

Just a thought,

I've been helping some people come up to speed on arduino,
  they are all working on projects that need to take in controls form buttons an keypads,

and they have all come up with different libs from the arduino sites.
  I did not realise there were so many different libs that are designed to cope with buttons.


I recently noticed there was a kickstarter project (now funded) that was trying to make it simpler for non-programmers to create microcontroller projects.  I don't know if it would be useful to you, or not.  http://www.modk.it/.


Suggestion , I'd guess that a large majority of arduino projects take in a sensor or two, that could be a button class,

I don't suppose that we could have one standard library to handle buttons effectively ?
  how about one that can handle all sorts of button sensors, key pads scanned and none scanned.

As I say, i know there are different libs for all these, I think my students have found every combination possible, which in some ways is good, it just makes using and debugging much harder than it should be for a simple function like reading a switch.


Yes, I came to the same conclusion.  I recently implemented my own button class library.  It has classes to handle pull down digital buttons, pull up digital buttons, analog sensors, nop buttons (which are useful to disable parts of the code when you are switching things around on the breadboard), and blink buttons which cycle between on/off at given times.

I have a few improvements I want to do, such as add read multiple buttons with a combined debounce timeout, add an elapsed function that returns how many milliseconds it has been since the button changed state, and add support for my LCD shield that has several buttons multiplexed on a single analog input.

The current code is at: http://www.the-meissners.org/arduino/MrmButton.zip

Unfortunately, it is now too large to post within code tags.

As an example, if I have a digital button with a resistor (pull down), I would do:

Code: [Select]

#include "MrmButton.h"

const int button_pin = 2;

Mrmbutton_pulldown button (button_pin);

void setup (void)
{
    button.setup ();
}

void loop (void)
{
    int value;

    // only do something if the button changed state
    if (button.read (&value)) {
        if (value) {
            // do action if button was just pressed
        } else {
            // do action if button was just released
        }
    }
}


Now, lets assume I want to change the button from a pull down button to a pull up button (and remove the resistor).  All you need to do is change the declaration of 'button':

Code: [Select]

Mrmbutton_pullup button (button_pin);


All of the rest of the tests stay the same.  You don't have to go through and change all == HIGH to == LOW.

drjiohnsmith

very nice,

I have seen many versions , and I have a few myself
    I was just thinking as buttons are so prevalent on arduion
         why is there no standard library...


Go Up