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 7:56d8df0eb209, committed 2017-07-02
- Comitter:
- johnb
- Date:
- Sun Jul 02 15:26:57 2017 +0000
- Parent:
- 6:ac481535732f
- Commit message:
- Updated threshold value & added comments
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 Sun Jul 02 15:05:19 2017 +0000
+++ b/freetronicsLCDShield.cpp Sun Jul 02 15:26:57 2017 +0000
@@ -30,7 +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 */
+const float freetronicsLCDShield::buttonThresholds[FREETRONICSLCDSHIELD_BUTTON_COUNT] = { 0.95, 0.65, 0.4, 0.15, -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) {
--- a/freetronicsLCDShield.h Sun Jul 02 15:05:19 2017 +0000
+++ b/freetronicsLCDShield.h Sun Jul 02 15:26:57 2017 +0000
@@ -1,5 +1,7 @@
/* mbed freetronicsLCDShield Library, written by Koen J.F. Kempeneers
* kkempeneers@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
@@ -26,9 +28,9 @@
#define LEFT 0
#define RIGHT 1
+/** Number of detectable buttons on the shield, Left, Right, Up, Down, plus one for "No button" */
#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
@@ -170,10 +172,22 @@
/** Reads the status of the buttons
*
- *
+ * This function returns the ADC value of the input connected to the buttons. When no button is pressed, this input is pulled high.
+ * If any button is pressed, the input is connected to ground via a resistor & the function will return a value less than 1.0,
+ * depending on the button. Approximate values (sourced from the schematic) are:
+ * Left: 2.47V -> ADC 0.748
+ * Down: 1.61V -> ADC 0.488
+ * Up: 0.71V -> ADC 0.215
+ * Right: 0.00V -> ADC 0.000
+ * Note that as ADC inputs are referenced to 3.3V, the select button cannot be read (as the voltage when this buttong is pressed is 3.62V,
+ * saturating the input and indistinguishable from no button being pressed.
*/
float readButton(void);
+ /** Determines which of the buttons is currently pressed
+ *
+ * Note that the shield design means that multi-button detection is not practical
+ */
ShieldButton pressedButton(void);
protected:
@@ -181,6 +195,7 @@
virtual int _putc(int value);
virtual int _getc();
+ /** Lower thresholds for the ADC value for each push button on the shield */
static const float buttonThresholds[FREETRONICSLCDSHIELD_BUTTON_COUNT];
};
