Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of freetronicsLCDShield by
Revision 6:ac481535732f, committed 2017-07-02
- Comitter:
- johnb
- Date:
- Sun Jul 02 15:05:19 2017 +0000
- Parent:
- 5:fa933933ccd1
- Child:
- 7:56d8df0eb209
- Commit message:
- Add pressedButton to return specifically which button is currently pressed (if any)
Changed in this revision
| freetronicsLCDShield.cpp | Show annotated file Show diff for this revision Revisions of this file |
| freetronicsLCDShield.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/freetronicsLCDShield.cpp Sat Dec 13 09:22:05 2014 +0000
+++ b/freetronicsLCDShield.cpp Sun Jul 02 15:05:19 2017 +0000
@@ -1,5 +1,7 @@
/* mbed freetronicsLCDShield Library, written by Koen J.F. Kempeneers
* kkempeneers(at)skynet.be
+ * Improved button support added by John Bailey
+ * jdb__mbed(at)anotherdimension.net
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -28,6 +30,7 @@
wait(0.000001f); \
_e = 1;
+const float freetronicsLCDShield::buttonThresholds[FREETRONICSLCDSHIELD_BUTTON_COUNT] = { 0.95, 0.65, 0.4, 0.20, -0.5 }; /* None, Left, Down, Up, Right */
freetronicsLCDShield::freetronicsLCDShield (PinName rs, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, PinName bl, PinName a0)
: _rs(rs), _e(e), _d(d0, d1, d2, d3), _bl(bl), _a0(a0) {
@@ -136,6 +139,20 @@
return(_a0.read());
}
+freetronicsLCDShield::ShieldButton freetronicsLCDShield::pressedButton(void) {
+ freetronicsLCDShield::ShieldButton retVal = freetronicsLCDShield::None;
+ float buttonVal = readButton();
+ for( unsigned i = 0; i < FREETRONICSLCDSHIELD_BUTTON_COUNT; i++ )
+ {
+ if( buttonVal > buttonThresholds[ i ] )
+ {
+ retVal = (ShieldButton)i;
+ break;
+ }
+ }
+ return retVal;
+}
+
// Virtual functions for stream
int freetronicsLCDShield::_putc(int value) {
writeData(value);
--- a/freetronicsLCDShield.h Sat Dec 13 09:22:05 2014 +0000
+++ b/freetronicsLCDShield.h Sun Jul 02 15:05:19 2017 +0000
@@ -26,6 +26,9 @@
#define LEFT 0
#define RIGHT 1
+#define FREETRONICSLCDSHIELD_BUTTON_COUNT 5
+
+
/**
* Provides full LCD support for the HD44780 compatible LCD on the arduino shaped shield.
* http://www.freetronics.com/products/lcd-keypad-shield#.UnIr6_nkq0M
@@ -156,16 +159,29 @@
*/
void home(void);
+ typedef enum
+ {
+ None,
+ Left,
+ Down,
+ Up,
+ Right
+ } ShieldButton;
+
/** Reads the status of the buttons
*
*
*/
float readButton(void);
+ ShieldButton pressedButton(void);
+
protected:
// Stream implementation functions
virtual int _putc(int value);
virtual int _getc();
+
+ static const float buttonThresholds[FREETRONICSLCDSHIELD_BUTTON_COUNT];
};
#endif
\ No newline at end of file
