Adjusts the great pinscape controller to work with a cheap linear potentiometer instead of the expensive CCD array

Dependencies:   USBDevice mbed

Fork of Pinscape_Controller by Mike R

Revision:
5:a70c0bce770d
Parent:
3:3514575d4f86
--- a/MMA8451Q/MMA8451Q.cpp	Thu Jul 24 05:50:36 2014 +0000
+++ b/MMA8451Q/MMA8451Q.cpp	Sun Jul 27 18:24:51 2014 +0000
@@ -66,10 +66,13 @@
 
 MMA8451Q::MMA8451Q(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) 
 {
-    // go to standby mode
-    standby();
-    
-#if 0
+    // initialize parameters
+    init();
+}
+
+// reset the accelerometer and set our parameters
+void MMA8451Q::init()
+{    
     // reset all registers to power-on reset values
     uint8_t d0[2] = { REG_CTRL_REG_2, 0x40 };
     writeRegs(d0,2 );
@@ -78,7 +81,9 @@
     do {
         readRegs(REG_CTRL_REG_2, d0, 1);
     } while ((d0[0] & 0x40) != 0);
-#endif
+    
+    // go to standby mode
+    standby();
     
     // read the curent config register
     uint8_t d1[1];
@@ -145,9 +150,14 @@
     uint8_t d1[1];
     readRegs(REG_CTRL_REG_1, d1, 1);
     
-    // write it back witht he Active bit cleared
-    uint8_t d2[2] = { REG_CTRL_REG_1, d1[0] & ~CTL_ACTIVE };
-    writeRegs(d2, 2);
+    // wait for standby mode
+    do {
+        // write it back with the Active bit cleared
+        uint8_t d2[2] = { REG_CTRL_REG_1, d1[0] & ~CTL_ACTIVE };
+        writeRegs(d2, 2);
+    
+        readRegs(REG_CTRL_REG_1, d1, 1);
+    } while (d1[0] & CTL_ACTIVE);
 }
 
 void MMA8451Q::active()