Base program for project 2 NMHU
Dependencies: SLCD mbed-rtos mbed
Fork of rtos_basic by
Revision 7:93ca18251991, committed 2015-02-22
- Comitter:
- scohennm
- Date:
- Sun Feb 22 18:31:04 2015 +0000
- Parent:
- 6:209f4db62daf
- Commit message:
- Random LED flasher and LCD. display using RTOS library. NMHU project 2
Changed in this revision
diff -r 209f4db62daf -r 93ca18251991 SLCD.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SLCD.lib Sun Feb 22 18:31:04 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/SLCD/#ef2b3b7f1b01
diff -r 209f4db62daf -r 93ca18251991 main.cpp --- a/main.cpp Tue Jun 04 16:01:32 2013 +0100 +++ b/main.cpp Sun Feb 22 18:31:04 2015 +0000 @@ -1,21 +1,81 @@ #include "mbed.h" #include "rtos.h" - -DigitalOut led1(LED1); -DigitalOut led2(LED2); +#include "SLCD.h" + +#define RANDLIMIT 2000 +#define RANDOFFSET 200 +#define T1INTERVAL 750 // ms +#define T2INTERVAL 500 // ms +#define BUTTON_INT 100 //ms +#define NUMSTATES 2 +#define GDISPLAY 0 +#define RDISPLAY 1 +#define LCDLEN 10 +#define LEDON 0 +#define LEDOFF 1 + +SLCD slcd; //define LCD display -void led2_thread(void const *args) { +DigitalOut gLed(LED_GREEN); +DigitalOut rLed(LED_RED); +int LButtonState; +DigitalIn LftButton(PTC3); +int displayState; +char LCDActual[LCDLEN]; + + +void LCDMess(char *lMess){ + slcd.Home(); + slcd.clear(); + slcd.printf(lMess); +} +void LCDdis_thread(void const *args){ + while(true) { + LCDMess(LCDActual); + Thread::wait(BUTTON_INT); + } +} +void button_thread(void const *args) { + int LButtonState; while (true) { - led2 = !led2; - Thread::wait(1000); + LButtonState = !LftButton; + if (LButtonState) { //Change data that is displayed cycle through states + displayState++; + displayState = displayState % NUMSTATES; + } + Thread::wait(BUTTON_INT); + } +} + + +void gLed_thread(void const *args) { + int interval; + while (true) { + gLed = !gLed; + interval = rand()% RANDLIMIT + RANDOFFSET; + if(displayState == GDISPLAY) { + sprintf (LCDActual, "Y.%3d", interval/10); + } + Thread::wait(interval); } } int main() { - Thread thread(led2_thread); + srand(time(NULL)); + int interval; + Thread gthread(gLed_thread); + Thread bthread(button_thread); + Thread lthread(LCDdis_thread); - while (true) { - led1 = !led1; - Thread::wait(500); + rLed = LEDON; + gLed = LEDOFF; + + while (true) { // Red LED thread + rLed = !rLed; + interval = rand()% RANDLIMIT + RANDOFFSET; + if(displayState == RDISPLAY) { + sprintf (LCDActual, "R.%d",interval/10); + } + Thread::wait(interval); } }
diff -r 209f4db62daf -r 93ca18251991 mbed-rtos.lib --- a/mbed-rtos.lib Tue Jun 04 16:01:32 2013 +0100 +++ b/mbed-rtos.lib Sun Feb 22 18:31:04 2015 +0000 @@ -1,1 +1,1 @@ -https://mbed.org/users/mbed_official/code/mbed-rtos/ \ No newline at end of file +https://mbed.org/users/mbed_official/code/mbed-rtos/#34e80e862021
diff -r 209f4db62daf -r 93ca18251991 mbed.bld --- a/mbed.bld Tue Jun 04 16:01:32 2013 +0100 +++ b/mbed.bld Sun Feb 22 18:31:04 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/ \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/6213f644d804 \ No newline at end of file