Skip to content

dncoder/MFShield

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi Function Shield Library

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.

picture

What is does

  • 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 durationbeep (int ms)

Quick start

  1. Download and unpack a ZIP archive to your Arduino/libraries folder, rename folder MFShield-master to MFShield.
  2. Open Arduino IDE and create a new sketch
  3. Include the library in your sketch by #include <MFShield.h>
  4. Create an instance of class MFShield: MFShield mfs;
  5. 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.

TODO

- Display negative and floating point numbers

About

A tiny and complete library for Arduino Multifunction Shield

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages