noop din
/
TSI_sample
Lab5 code
Fork of TSI_sample by
Revision 5:36c887c458f9, committed 2018-03-02
- Comitter:
- toh2018
- Date:
- Fri Mar 02 11:18:59 2018 +0000
- Parent:
- 4:d54e74fbf82c
- Commit message:
- first commit
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed_app.json | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Feb 22 16:59:24 2018 +0000 +++ b/main.cpp Fri Mar 02 11:18:59 2018 +0000 @@ -10,10 +10,17 @@ Serial pc(USBTX, USBRX); // tx, rx DigitalOut redLED(LED_RED); DigitalOut greenLED(LED_GREEN); +DigitalOut blueLED(LED_BLUE); +DigitalOut led1(D9); + + TSISensor tsi; -Thread redThread ; // thread for red LED -Thread greenThread ; // thread for green LED +Thread redThread ; // thread for red LED +Thread greenThread ; // thread for green LED +Thread blueThread; // thread for blue LED +Thread yellowThread ; // thread for yellow LED +Thread position; // thread position void red_thread() { // method to run in thread while (true) { @@ -39,21 +46,74 @@ } } +// implement more thread + +// this is more thread + +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 + blueThread.signal_clr(0x1) ; + // Signal are automatically cleared by wait_signal but + // the signal might have been set again while LED on + } +} + +// this is for addititonal yellow + + +void yellow_thread() { // method to run in thread + while (true) { + Thread::signal_wait(0x1); + led1 = false ; // turn on + Thread::wait(5000); + led1 = true; // turn off + yellowThread.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 + blueLED = true; // turn off + led1 = true; + //yellowLED = true; // turn off + redThread.start(&red_thread) ; // start the red thread greenThread.start(&green_thread) ; // start the green thread + blueThread.start(&blue_thread) ; // start the blue thread + yellowThread.start(&yellow_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.printf("%d \n \r", d) ; pc.putc(' ') ; - 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 + if (d > 3 && d < 9) { + redThread.signal_set(0x1) ; + } + else if (d > 13 && d < 19) { + greenThread.signal_set(0x1) ; + } + else if (d > 23 && d < 29) { + blueThread.signal_set(0x1) ; + } + else if (d > 33 ) { + yellowThread.signal_set(0x1) ; + } + else{ + + + + } + Thread::wait(50); // This polling rate is too slow - increase it // The slower rate maks it easier to output on the terminal } } \ No newline at end of file
--- a/mbed_app.json Thu Feb 22 16:59:24 2018 +0000 +++ b/mbed_app.json Fri Mar 02 11:18:59 2018 +0000 @@ -1,7 +1,7 @@ { "config": { - "main-stack-size": { - "value": 2000 + "thread-stack-size": { + "value": 1000 } } } \ No newline at end of file