deni setiawan
/
TSI_sample_lab5_part2
fix deni
Fork of TSI_sample by
Revision 5:e79b003f2bc5, committed 2018-03-01
- Comitter:
- dhenis
- Date:
- Thu Mar 01 21:04:55 2018 +0000
- Parent:
- 4:d54e74fbf82c
- Commit message:
- fix'
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r d54e74fbf82c -r e79b003f2bc5 main.cpp --- a/main.cpp Thu Feb 22 16:59:24 2018 +0000 +++ b/main.cpp Thu Mar 01 21:04:55 2018 +0000 @@ -10,18 +10,40 @@ Serial pc(USBTX, USBRX); // tx, rx DigitalOut redLED(LED_RED); DigitalOut greenLED(LED_GREEN); +DigitalOut blueLED(LED_BLUE); + +DigitalOut ledex1(D0); + TSISensor tsi; +//Thread redThread(osPriorityNormal, 1000); +//Thread greenThread(osPriorityNormal, 1000); + -Thread redThread ; // thread for red LED -Thread greenThread ; // thread for green LED +Thread outterleft(osPriorityNormal, 1000); +Thread innerleft(osPriorityNormal, 1000); +Thread innerlight(osPriorityNormal, 1000); +Thread outerright(osPriorityNormal, 1000); // this thread doesnt work, so I directly move it into main thread + +//Thread redThread ; // thread for red LED +//Thread greenThread ; // thread for green LED + bool red = true,green = true,blue = true,white = true; + + + 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) ; + + + redLED = !redLED ; // turn on + + outterleft.signal_clr(0x1) ; + + // Signal are automatically cleared by wait_signal but // the signal might have been set again while LED on } @@ -29,30 +51,178 @@ 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) ; + +// green = false ; + greenLED = !greenLED ; // turn on + + innerleft.signal_clr(0x1) ; + + + + // Signal are automatically cleared by wait_signal but + // the signal might have been set again while LED on + } +} + +void blue_thread() { // method to run in thread + while (true) { + + + Thread::signal_wait(0x1); +// blue = false; + + blueLED = !blueLED ; // turn on + innerlight.signal_clr(0x1) ; + + + + // Signal are automatically cleared by wait_signal but + // the signal might have been set again while LED on + } +} + +void white_thread() { // method to run in thread + while (true) { + // + Thread::signal_wait(0x1); + + + ledex1 = !ledex1; + // +// blueLED = !blueLED ; // turn off +// greenLED = !greenLED; // turn off +// redLED = !redLED ; // turn off + + outerright.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 + int position = 1; //checking state + + outterleft.start(&red_thread) ; // start the red thread + innerleft.start(&green_thread) ; // start the green thread + innerlight.start(&blue_thread) ; // start the green thread + outerright.start(&white_thread) ; // start the green thread + + + blueLED = true ; // turn off + greenLED = true; // turn off + redLED = true ; // turn off + + ledex1 = false; + while (true) { - uint8_t d = tsi.readDistance() ; // Distance is between 0 and 39 +// 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) ; + // signals are triggered by touching the sri + // signal set on addres 0x1 + + uint8_t pos = tsi.readDistance() ; // Distance is between 0 and 39 + +// +// redLED = true; +// greenLED = true; +// blueLED = true; + + if(pos >3 and pos < 9){ // softkey outterleft + + + //state entry +// redLED = !redLED ; // turn on + if(position == 1){ + + outterleft.signal_set(0x1) ; + + position = 0; + + } + + + }else if(pos ==3 or pos ==9){ + //state exit + redLED = true; // turn of +// outterleft.signal_set(0x1) ; + + + }else if(pos >13 and pos < 19){// softkey innerleft + //state entry + // greenLED = !greenLED; // turn on + + if(position == 1){ + + innerleft.signal_set(0x1) ; + + position = 0; + } + + }else if(pos ==13 or pos ==19){ + //state exit + greenLED = true; // turn of + + // innerleft.signal_set(0x2) ; + + + }else if(pos >23 and pos < 29){ // softkey innerlight + //state entry + // blueLED = !blueLED; // turn on + + if(position == 1){ + + innerlight.signal_set(0x1) ; + + position = 0; + } + + }else if(pos ==23 or pos ==29){ + //state exit + blueLED = true; // turn of + + + + }else if(pos >=34 and pos <40){ // softkye outerright + //state entry + + if(position == 1){ + + ledex1 = !ledex1; + + position = 0; + } + + + } + else if(pos ==33){ + //state exit + + ledex1 = false; + + + } + else if(pos == 0) { + position = 1; + + + } + + + + + pc.printf("%d \n \r", pos ) ; pc.putc(' ') ; - if (d == 10) redThread.signal_set(0x1) ; - if (d == 20) greenThread.signal_set(0x1) ; +// 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 // The slower rate maks it easier to output on the terminal }