Class to drive a array of push buttons.
Public declarations:
class ButtonOwner{ public: virtual void buttonPressed(byte btID){} virtual void buttonReleased(byte btID){} }; class PushButtonArray{ public: byte btCount=0; PushButton** but; PushButtonArray(); PushButtonArray(ButtonOwner *owner); boolean begin(byte maxButtons); int addButton(byte buttonPin, boolean pullUp=true); void run(); boolean isPressed(byte btID); protected: virtual void onButtonPressed(byte btID){} virtual void onButtonReleased(byte btID){} };
Call begin() before any method informing how many buttons you want in array. Dont forget to check begin() return to make sure that the array was successfully allocated.
Add buttons to array calling addButton() informing pin and input mode.
Call run() at least once per loop to class trigger events.
Call isPressed() to check if one button is pressed.
ButtonOwner
Is a abstract class to receive button's events. This is usefull when the class that respond the events, is not descending of PushButtonArray class. To use this way, derive ButtonOwner class, rewrite the events and use the constructor with owner to create PushButtonArray's instance.
Constructor with button's owner. If you use this constructor, events will be send to owner and not to PushButtonArray class.
owner: ButtonOwner instance. Events are sent to owner.
Call before any other method. This method alloc the array, check the return to make sure that the array was successfully allocated.
Add button on array.
Call once per loop. This method trigger the events.
Call to check if one button is pressed or not.
btID: ID of button
return: true if the button is pressed , false if not.
Event triggered when one button is pressed. To capture this event, derive PushButtonArray class and rewrite it.
This event is not triggered if the constructor with owner is used.
btID: ID of button
Event triggered when button is released. To capture this event, derive PushButtonArray class and rewrite it.
This event is not triggered if the constructor with owner is used.
btID: ID of button
Wiki: Home
Wiki: JoyStickShield
Wiki: JsRadioMaster
Wiki: JsRadioSlave