Sebastian Barrera
/
Lab5_part2
lab 5 part 2
Diff: main.cpp
- Revision:
- 8:ca714e821245
- Parent:
- 7:a910936bf4f8
- Child:
- 9:595d1dbf0086
diff -r a910936bf4f8 -r ca714e821245 main.cpp --- a/main.cpp Thu Mar 12 11:59:07 2020 +0000 +++ b/main.cpp Mon Mar 16 11:37:43 2020 +0000 @@ -23,37 +23,44 @@ # define rin 0x04 # define rout 0x08 EventFlags signals; +volatile uint32_t flags_red; + +volatile uint32_t flags_green; void changebrightnessred() { // method to run in thread - int flags; float i=0; while (true) { - signals.wait_any(lin,false); - flags=signals.wait_any(lout|rout,true); - if (flags==lout){ + signals.wait_any(lin,osWaitForever,false); + signals.clear(rin); + flags_red=signals.wait_any(lout|rout,osWaitForever,true); + if (flags_red==lout){ if (i!=0) i--; } - if (flags==rout){ + if (flags_red==rout){ if (i!=9) i++; } - pc.printf("flag: %d, red: %d",flags, i); + signals.clear(lout); + signals.clear(rout); + pc.printf("red: %f \n ", i); redLED= i/10; } } void changebrightnessgreen() { // method to run in thread - int flags; float i=0; while (true) { - signals.wait_any(rin,false); - flags=signals.wait_any(lout|rout,true); - if (flags==lout){ + signals.wait_any(rin,osWaitForever,false); + signals.clear(lin); + flags_green=signals.wait_any(lout|rout,osWaitForever,true); + if (flags_green==lout){ if (i!=0) i--; } - if (flags==rout){ + if (flags_green==rout){ if (i!=9) i++; } - pc.printf("green: %d", i); + signals.clear(lout); + signals.clear(rout); + pc.printf("green: %f \n", i); greenLED= i/10; } } @@ -76,17 +83,17 @@ if (d>33){pos=ro; signals.set(rout); t.start();} break; case lo: - if (t.read()>1) signals.set(lout); + if (t.read()>1) {signals.set(lout); t.reset();} if (d<3 || d>9) {pos=neutral; t.reset(); t.stop();} break; case li: - if (d<13 || d>19) {pos=neutral; signals.clear(lin);} + if (d<13 || d>19) {pos=neutral; } break; case ri: - if (d<23 || d>29) {pos=neutral; signals.clear(rin);} + if (d<23 || d>29) {pos=neutral; } break; case ro: - if (t.read()>1) signals.set(rout); + if (t.read()>1) {signals.set(rout);t.reset();} if (d<33) {pos=neutral; t.reset(); t.stop();} break; }