-

Dependencies:   mbed MPU6050 mbed-rtos SpiFlash25 HMC5883L BMP085 flash-fs ledControl2

Committer:
mbentata
Date:
Tue Oct 16 14:31:19 2018 +0000
Revision:
0:b487734d687d
Child:
1:42e428d934fe
RTOS Lab code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbentata 0:b487734d687d 1 #include "mbed.h"
mbentata 0:b487734d687d 2 #include "uLCD_4DGL.h"
mbentata 0:b487734d687d 3 #include "rtos.h"
mbentata 0:b487734d687d 4 #include "stdio.h"
mbentata 0:b487734d687d 5
mbentata 0:b487734d687d 6 uLCD_4DGL uLCD(p13,p14,p30);
mbentata 0:b487734d687d 7 PwmOut RGBLED_r(p23);
mbentata 0:b487734d687d 8 PwmOut RGBLED_g(p24);
mbentata 0:b487734d687d 9 PwmOut RGBLED_b(p25);
mbentata 0:b487734d687d 10 Mutex lcd_mutex;
mbentata 0:b487734d687d 11
mbentata 0:b487734d687d 12
mbentata 0:b487734d687d 13 void thread1(void const *args)
mbentata 0:b487734d687d 14 {
mbentata 0:b487734d687d 15 while(true) { // thread loop
mbentata 0:b487734d687d 16 RGBLED_r = 0.5 + (rand() % 11)/20.0;
mbentata 0:b487734d687d 17 RGBLED_g = 0.5 + (rand() % 11)/20.0;
mbentata 0:b487734d687d 18 RGBLED_b = 0.5 + (rand() % 11)/20.0;
mbentata 0:b487734d687d 19 Thread::wait(300); // wait 1.5s
mbentata 0:b487734d687d 20 }
mbentata 0:b487734d687d 21 }
mbentata 0:b487734d687d 22
mbentata 0:b487734d687d 23 void thread2(void const *args)
mbentata 0:b487734d687d 24 {
mbentata 0:b487734d687d 25 while(true) { // thread loop
mbentata 0:b487734d687d 26 lcd_mutex.lock();
mbentata 0:b487734d687d 27 // basic printf demo = 16 by 18 characters on screen
mbentata 0:b487734d687d 28 uLCD.printf("\nHello uLCD World\n"); //Default Green on black text
mbentata 0:b487734d687d 29 uLCD.printf("\n Starting Demo...");
mbentata 0:b487734d687d 30 uLCD.text_width(4); //4X size text
mbentata 0:b487734d687d 31 uLCD.text_height(4);
mbentata 0:b487734d687d 32 uLCD.color(RED);
mbentata 0:b487734d687d 33 for (int i=10; i>=6; --i) {
mbentata 0:b487734d687d 34 uLCD.locate(1,2);
mbentata 0:b487734d687d 35 uLCD.printf("%2D",i);
mbentata 0:b487734d687d 36 wait(.5);
mbentata 0:b487734d687d 37 }
mbentata 0:b487734d687d 38 uLCD.cls();
mbentata 0:b487734d687d 39 lcd_mutex.unlock();
mbentata 0:b487734d687d 40 Thread::wait(1000);
mbentata 0:b487734d687d 41 }
mbentata 0:b487734d687d 42 }
mbentata 0:b487734d687d 43
mbentata 0:b487734d687d 44
mbentata 0:b487734d687d 45 void thread3(void const *args)
mbentata 0:b487734d687d 46 {
mbentata 0:b487734d687d 47 while(true) { // thread loop
mbentata 0:b487734d687d 48 lcd_mutex.lock();
mbentata 0:b487734d687d 49 // basic printf demo = 16 by 18 characters on screen
mbentata 0:b487734d687d 50 uLCD.printf("\nHello uLCD World\n"); //Default Green on black text
mbentata 0:b487734d687d 51 uLCD.printf("\n Starting Demo...");
mbentata 0:b487734d687d 52 uLCD.text_width(4); //4X size text
mbentata 0:b487734d687d 53 uLCD.text_height(4);
mbentata 0:b487734d687d 54 uLCD.color(RED);
mbentata 0:b487734d687d 55 for (int i=5; i>=0; --i) {
mbentata 0:b487734d687d 56 uLCD.locate(1,2);
mbentata 0:b487734d687d 57 uLCD.printf("%2D",i);
mbentata 0:b487734d687d 58 wait(.5);
mbentata 0:b487734d687d 59 }
mbentata 0:b487734d687d 60 uLCD.cls();
mbentata 0:b487734d687d 61 lcd_mutex.unlock();
mbentata 0:b487734d687d 62 Thread::wait(1000);
mbentata 0:b487734d687d 63 }
mbentata 0:b487734d687d 64 }
mbentata 0:b487734d687d 65
mbentata 0:b487734d687d 66 int main() {
mbentata 0:b487734d687d 67 Thread t1(thread1);
mbentata 0:b487734d687d 68 Thread t2(thread2);
mbentata 0:b487734d687d 69 Thread t3(thread3);
mbentata 0:b487734d687d 70 while(1) {
mbentata 0:b487734d687d 71 lcd_mutex.lock();
mbentata 0:b487734d687d 72 lcd_mutex.unlock();
mbentata 0:b487734d687d 73 Thread::wait(500);
mbentata 0:b487734d687d 74 }
mbentata 0:b487734d687d 75 }