first version

Dependencies:   TSI

Fork of TSI_sample by William Marsh

Files at this revision

API Documentation at this revision

Comitter:
WilliamMarshQMUL
Date:
Wed Feb 15 11:45:56 2017 +0000
Child:
1:e6ffa08ad8bf
Commit message:
First version

Changed in this revision

TSI.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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSI.lib	Wed Feb 15 11:45:56 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/mbed/code/TSI/#1a60ef257879
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Feb 15 11:45:56 2017 +0000
@@ -0,0 +1,59 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "TSISensor.h"
+
+// Example program for lab 5
+// -------------------------
+//  A value is read from the touch sensor and use
+//    to control two LEDs
+//  The value is also output to the serial interface
+
+Serial pc(USBTX, USBRX); // tx, rx
+DigitalOut redLED(LED_RED);
+DigitalOut greenLED(LED_GREEN);
+TSISensor tsi;
+
+Thread redThread ; // thread for red LED
+Thread greenThread ; // thread for green LED
+ 
+void red_thread() {  // method to run in thread
+    while (true) {
+        Thread::signal_wait(0x1);
+        redLED = false ; // turn on 
+        Thread::wait(5000);
+        redLED = true ; // turn off 
+        redThread.signal_clr(0x1) ;
+          // Signal are automatically cleared by wait_signal but
+          // the signal might have been set again while LED on 
+    }
+}
+
+void green_thread() {  // method to run in thread
+    while (true) {
+        Thread::signal_wait(0x1);
+        greenLED = false ; // turn on 
+        Thread::wait(5000);
+        greenLED = true ; // turn off 
+        greenThread.signal_clr(0x1) ;
+          // Signal are automatically cleared by wait_signal but
+          // the signal might have been set again while LED on 
+    }
+}
+
+int main(void) {
+    redLED = true ; // turn off 
+    greenLED = true ; // turn off 
+    redThread.start(&red_thread) ; // start the red thread
+    greenThread.start(&green_thread) ; // start the green thread
+    
+    while (true) {
+        uint8_t d = tsi.readDistance() ;  // Distance is between 0 and 39
+                                          // When no touch --> 0
+                                          // Left --> low value  Right --> high value
+        pc.printf("%d", d) ;  
+        pc.putc(' ') ;                                
+        Thread::wait(200);
+        if (d == 10) redThread.signal_set(0x1) ;
+        if (d == 20) greenThread.signal_set(0x1) ;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Wed Feb 15 11:45:56 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Feb 15 11:45:56 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/99b5ccf27215
\ No newline at end of file