Example Hello World example for interfacing the AT42QT1010 Device

Dependencies:   AT42QT1010 mbed

Files at this revision

API Documentation at this revision

Comitter:
jnagendran3
Date:
Mon Oct 20 21:43:47 2014 +0000
Parent:
0:3009c861d060
Commit message:
Fixed interrupt routine

Changed in this revision

AT42QT1010.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/AT42QT1010.lib	Mon Oct 20 13:14:18 2014 +0000
+++ b/AT42QT1010.lib	Mon Oct 20 21:43:47 2014 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/jnagendran3/code/AT42QT1010/#7eca199a5506
+http://developer.mbed.org/users/jnagendran3/code/AT42QT1010/#401cf3c2dffc
--- a/main.cpp	Mon Oct 20 13:14:18 2014 +0000
+++ b/main.cpp	Mon Oct 20 21:43:47 2014 +0000
@@ -3,18 +3,42 @@
 
 DigitalOut read_led(LED1);
 DigitalOut auto_led(LED2);
-DigitalOut interrupt_led(LED3);
-AT42QT1010 touch_sensor(p21,p23);
+DigitalOut i_led1(LED3);
+DigitalOut i_led2(LED4);
+AT42QT1010 touch_sensor(p23,p21);
+
+//Global variables to control interrupt timing
+int _old_sig=0;
+int _new_sig=0;
 
-void interrupt(){
-    interrupt_led=!interrupt_led;
+void rise_interrupt(){
+    static int count=0;
+    //Only execute on true rise
+    if(_old_sig==0 && _new_sig==1){
+        _old_sig=1;
+        //Use LED3 and LED4 to display count
+        count++;
+        i_led2=(count)%2;
+        i_led1=(count>>1)%2;
+    }  
+}
+void fall_interrupt(){
+    //Trigger indication of true fall
+    if(_new_sig==0) _old_sig=0;
 }
 
 int main() {
-    touch_sensor.attach(&interrupt);
+    //Set up the rising and falling edge interrupts
+    touch_sensor.attach_rise(&rise_interrupt);
+    touch_sensor.attach_fall(&fall_interrupt);
     while(1) {
+        //Declare the current status of the sensor,
+        //and give a window of time to process.
+        _new_sig = touch_sensor;
+        wait(.1);
+        //Member function demonstration
         read_led = touch_sensor.read();
         auto_led = touch_sensor;
-        touch_sensor.write(auto_led);
+        touch_sensor.write(!auto_led);
     }
 }