![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
first version
Fork of TSI_sample by
Diff: main.cpp
- Revision:
- 3:adf1bff83db6
- Parent:
- 1:e6ffa08ad8bf
- Child:
- 4:1654ec08fde4
--- a/main.cpp Wed Feb 14 21:42:51 2018 +0000 +++ b/main.cpp Thu Mar 01 02:10:30 2018 +0000 @@ -11,10 +11,14 @@ Serial pc(USBTX, USBRX); // tx, rx DigitalOut redLED(LED_RED); DigitalOut greenLED(LED_GREEN); +DigitalOut blueLED(LED_BLUE); + TSISensor tsi; -Thread redThread ; // thread for red LED -Thread greenThread ; // thread for green LED +Thread redThread(osPriorityNormal, 1000); // thread for red LED +Thread greenThread(osPriorityNormal, 1000); // thread for green LED +Thread blueThread(osPriorityNormal, 1000); // thread for green LED +Thread allThread(osPriorityNormal, 1000); // thread for green LED void red_thread() { // method to run in thread while (true) { @@ -40,18 +44,102 @@ } } +void blue_thread() { // method to run in thread + while (true) { + Thread::signal_wait(0x1); + blueLED = false ; // turn on + Thread::wait(5000); + blueLED = 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 all_thread() { // method to run in thread + while (true) { + Thread::signal_wait(0x1); + redLED = false; + greenLED = false ; // turn on + blueLED = false; + Thread::wait(5000); + greenLED = true ; // turn off + redLED = false; + blueLED = false; + greenThread.signal_clr(0x1) ; + // Signal are automatically cleared by wait_signal but + // the signal might have been set again while LED on + } +} + +enum softkeys {outer_left,inner_left,outer_right,inner_right, grey }; + 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 + softkeys key = grey; + while (true) { uint8_t d = tsi.readDistance() ; // Distance is between 0 and 39 + + + + + + // When no touch --> 0 // Left --> low value Right --> high value + if(d>3 && d <9) + { + key = outer_left; + + } + else + if( d>13 && d < 19) + { + key=inner_left; + + }else + if(d>23 && d < 29) + { + key = inner_right; + }else + if(d>33) + { + key = outer_right; + } + + switch(key){ + case outer_left : + if (d<3 || d >9 ) { // + key= grey; + } + break ; + case inner_left : + if (d<13 || d >19 ) { // + key= grey; + } + break ; + case inner_right : + if (d<23 || d >29 ) { // + key = grey; + } + break ; + case outer_right : + if (d<33) { // + key = grey; + } + break ; + } + + + pc.printf("%d", d) ; pc.putc(' ') ; + pc.printf("\r"); if (d == 10) redThread.signal_set(0x1) ; if (d == 20) greenThread.signal_set(0x1) ; Thread::wait(200); // This polling rate is too slow - increase it