Project 1D (final)

Dependencies:   MMA8451Q8b SLCD mbed

Fork of KL46z_single_tap_empty_DE_4_1_PROJECT1B_wInterrupts by David Estrada

Files at this revision

API Documentation at this revision

Comitter:
destradafilm
Date:
Mon Feb 16 03:09:11 2015 +0000
Parent:
5:ef2cfcf29f09
Commit message:
Project 1D (final)

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r ef2cfcf29f09 -r 52bf98447a11 main.cpp
--- a/main.cpp	Wed Feb 11 18:24:47 2015 +0000
+++ b/main.cpp	Mon Feb 16 03:09:11 2015 +0000
@@ -8,6 +8,8 @@
 #define LEDDELAY    0.75
 #define WAITDELAY   0.7
 #define LCDLEN      10
+#define TIMELIMIT   0x50 // Set time limit for Tap Detection to 50ms, Normal Mode
+#define LATENCYTIME 0xF0 // Set latency time to 300ms
 
 #define REG_WHO_AM_I      0x0D
 #define XYZ_DATA_CFG      0x0E
@@ -18,9 +20,9 @@
 #define REG_PULSE_SRC     0x22
 #define REG_PULSE_CFG     0x21
 
-#define PULSE_THSX        0x23
-#define PULSE_THSY        0x24
-#define PULSE_THSZ        0x25
+#define PULSE_THSX        0x23 // not activated for this project
+#define PULSE_THSY        0x24 // not activated for this project
+#define PULSE_THSZ        0x25 // REGISTER ACTIVATED TO BE INTERRUPT BUTTON WHEN Z IS TAPPED
 
 #define PULSE_TMLT        0x26
 
@@ -48,21 +50,22 @@
 #define MMA8451_I2C_ADDRESS (0x1d<<1)
  
 Ticker ledBlink; // timinginterrupt for RED led
-//InterruptIn mybutton(PTC3);  //push botton with internal pullup
+//InterruptIn mybutton(PTC3);  //(OLD INTERRUPT CODE) This was the right button with internal pullup
 
-// SWITCH BUTTON TO ACCELEROMETER
-InterruptIn mybutton(PTC5);
+//ACCELEROMETER pulse register in Z axis now Interrupt
+InterruptIn mybutton(PTC5); // MMA8451Q INT1
 
 DigitalOut myled(LED_RED); // red led
 DigitalOut relay(LED_GREEN); // green led
 
- MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
+ MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); // not sure what this does?
  
+// Variables to setup RELAY - (Relay switch is triggered by tap on z axis)
 float delay = WAITDELAY;
 int relayState = RELAYOFF;
 int outState = false;
 SLCD slcd; //define LCD display
-char LCDMessages[2][LCDLEN] = {"TRUE", "FALS"};
+char LCDMessages[2][LCDLEN] = {"TRUE", "FALS"}; // alternating messages to check that relay works
 
 
 void LCDMess(char *lMess, float dWait){
@@ -77,14 +80,13 @@
         slcd.printf(lMess);
 } 
 
-
 void LEDBlinker(){  // RED LED interrupt
     outState = !outState; 
     myled.write(outState);
 }
         
     
-void pressed() // button intterupt
+void pressed() // PTC5 intterupt
 {
     relayState = !relayState;
     relay.write(relayState);
@@ -100,11 +102,10 @@
     myled.write(outState);
     relay.write(relayState);
     
-// set up interrrupts to be used later for taps
-//    mybutton.fall(&pressed);
-    mybutton.rise(&pressed); // setup for PTC5, Accel.
+// set up interrrupts to be used for taps
+    mybutton.rise(&pressed); // setup for PTC5
     mybutton.mode(PullNone);
-// set up interrrupts to be used later for taps
+// set up interrrupts to be used for taps
     ledBlink.attach(&LEDBlinker, LEDDELAY);
     
 // Check to see if accerlometer is alive and well
@@ -128,19 +129,26 @@
 //        acc.setPulseConfiguration(latchData, axisData); // write the data
         acc.readRegs(REG_PULSE_CFG, &regData, 1);  // check it
         
-        // set z axis pulse THsZ
+        // set z axis pulse THsZ REGISTER TO ACTIVE (or 1) /// 0b00100000
         acc.setRegisterInStandby(PULSE_THSZ, 0x20);
         
+        // Set Time Limit
+        
+        
         // SET THE INTERRUPT
-        acc.setRegisterInStandby(CTRL_REG4, 0x08);
-        acc.setRegisterInStandby(CTRL_REG5, 0x08);
+        acc.setRegisterInStandby(CTRL_REG4, 0x08); // set bit 3 - Pulse Detection interrupt enabled
+        acc.setRegisterInStandby(CTRL_REG5, 0x08); // set bit 3 -  Interrupt is routed to INT1 pin
         
         
         
         sprintf (lcdData,"%x",regData);
         LCDMess(lcdData,BLINKTIME); 
         
+        // set Pulse TimeLimit
+        acc.setRegisterInStandby(PULSE_TMLT, TIMELIMIT);
         
+        //Set Latency Time
+        acc.setRegisterInStandby(PULSE_LTCY, LATENCYTIME);
         
         acc.readRegs(REG_PULSE_SRC, &regData, 1);
         sprintf (lcdData,"%x",regData);