A basic library for the Freetronics arduino LCD shield.

Fork of freetronicsLCDShield by Koen Kempeneers

Revision:
6:ac481535732f
Parent:
4:3a0c74cef8e8
Child:
7:56d8df0eb209
diff -r fa933933ccd1 -r ac481535732f freetronicsLCDShield.cpp
--- 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);