MFShield is a small and easy library for a common cheap Arduino Multi-Function Shield
Eliminates the need for using code snippets and pin definitions - you just simply call the library functions.
- Calls a function when a button is pressed:
onKeyPress(yourFunction (uint8_t button_number))
- Shows a number on the display:
display (int value)
- Reads the analog value of potentiometer:
int readTrimmerValue ()
- Emits a sound with buzzer for a given duration
beep (int ms)
- Download and unpack a ZIP archive to your Arduino/libraries folder, rename folder MFShield-master to MFShield.
- Open Arduino IDE and create a new sketch
- Include the library in your sketch by
#include <MFShield.h>
- Create an instance of class MFShield:
MFShield mfs;
- Add a
mfs.loop()
function in the main loop.
Basic example (click to view)
#include <MFShield.h>
MFShield mfs;
void setup ()
{
Serial.begin (9600);
/* Handle buttons */
mfs.onKeyPress ([](uint8_t button) {
mfs.beep(10); // make sound
mfs.setLed (button, !mfs.getLed(button)); // toggle onboard leds
Serial.println ("Button pressed: " + String(button));
});
}
void loop ()
{
/* Display seconds */
mfs.display (millis() / 1000);
mfs.loop();
/* ^ It's important to insert this loop function in the main loop
* else numeric display wont work
*/
}
Important: avoid to use delay()
and other blocking function in your sketch,
as it will prevent the library from updating the display and polling the buttons.
A much better practice would be to use millis()
instead.
See examples for detailed description.
- Display negative and floating point numbers