fork of original freetronics library

Dependents:   AwsomeStation

Fork of Freetronics_16x2_LCD by Components

Revision:
4:b4b2435f4a7f
Parent:
1:ddcefddda4a7
Child:
5:7b216d7781f8
--- a/freetronicsLCDShield.cpp	Thu Oct 31 14:26:31 2013 +0000
+++ b/freetronicsLCDShield.cpp	Thu Jun 02 13:31:16 2016 +0000
@@ -132,10 +132,56 @@
     writeByte(command);
 } 
 
-float freetronicsLCDShield::readButton(void) {
+float freetronicsLCDShield::readButtonAnalog(void) {
     return(_a0.read());
 }
 
+freetronicsLCDShield::ButtonType_t freetronicsLCDShield::readButton(void) {
+    float val;
+    
+    // read analog value
+    val = readButtonAnalog();
+    
+    // determine which button is pressed
+    // analog reading for each button are centered at 0, 144, 329, 504, 741, 1000
+    
+    // right
+    if (val < 0.0740f)
+    {
+        return freetronicsLCDShield::BTN_RIGHT;
+    }
+    
+    // up
+    else if (val < 0.2625f)
+    {
+        return freetronicsLCDShield::BTN_UP;
+    }
+    
+    // down
+    else if (val < 0.4855f)
+    {
+        return freetronicsLCDShield::BTN_DOWN;
+    }
+    
+    // left
+    else if (val < 0.6815f)
+    {
+        return freetronicsLCDShield::BTN_LEFT;
+    }
+    
+    // none
+    else if (val < 0.8465f)
+    {
+        return freetronicsLCDShield::BTN_NONE;
+    }
+    
+    // select
+    else
+    {
+        return freetronicsLCDShield::BTN_SELECT;
+    }
+}
+
 // Virtual functions for stream
 int freetronicsLCDShield::_putc(int value) {   
     writeData(value);