Karl Nicolaus / Mbed 2 deprecated 4180_Lab3_P3_DNU

Dependencies:   mbed wave_player mbed-rtos 4DGL-uLCD-SE SDFileSystem_OldbutworkswithRTOS

Files at this revision

API Documentation at this revision

Comitter:
kanicolaus
Date:
Sat Feb 23 20:24:29 2019 +0000
Parent:
1:5b8e223e983d
Commit message:
Testing "publishing" function

Changed in this revision

4DGL-uLCD-SE.lib Show annotated file Show diff for this revision Revisions of this file
RGBLed/RGBLed.cpp Show annotated file Show diff for this revision Revisions of this file
RGBLed/RGBLed.h Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/4DGL-uLCD-SE.lib	Sat Feb 23 20:24:29 2019 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RGBLed/RGBLed.cpp	Sat Feb 23 20:24:29 2019 +0000
@@ -0,0 +1,16 @@
+#include "RGBLed.h"
+#include "mbed.h"
+
+RGBLed::RGBLed (PinName redpin, PinName greenpin, PinName bluepin)
+    : _redpin(redpin), _greenpin(greenpin), _bluepin(bluepin)
+{
+    //50Hz PWM clock default a bit too low, go to 2000Hz (less flicker)
+    _redpin.period(0.0005);
+}
+ 
+void RGBLed::write(float red,float green, float blue)
+{
+    _redpin = red;
+    _greenpin = green;
+    _bluepin = blue;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RGBLed/RGBLed.h	Sat Feb 23 20:24:29 2019 +0000
@@ -0,0 +1,12 @@
+#include "mbed.h"
+//Class to control an RGB LED using three PWM pins
+class RGBLed
+{
+public:
+    RGBLed(PinName redpin, PinName greenpin, PinName bluepin);
+    void write(float red,float green, float blue);
+private:
+    PwmOut _redpin;
+    PwmOut _greenpin;
+    PwmOut _bluepin;
+};
\ No newline at end of file
--- a/SDFileSystem.lib	Thu Jan 24 02:59:05 2013 +0000
+++ b/SDFileSystem.lib	Sat Feb 23 20:24:29 2019 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
+https://developer.mbed.org/users/4180_1/code/SDFileSystem_OldbutworkswithRTOS/#e6c086545857
--- a/main.cpp	Thu Jan 24 02:59:05 2013 +0000
+++ b/main.cpp	Sat Feb 23 20:24:29 2019 +0000
@@ -1,20 +1,127 @@
-
+//Include required libraries (uLCD, mbed, rtos, etc.)
 #include "mbed.h"
-#include "SDFileSystem.h"
-#include "wave_player.h"
+#include "rtos.h"
+//#include "uLCD_4DGL.h"
+//#include "wave_player.h"
+//#include "stdio.h"
+//#include "RGBLed.h"
+//#include "SDFileSystem.h"
 
+//Initialize all objects
+//uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin;
+//SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
+//RawSerial  blue(p13,p14);
+//RGBLed myRGB(p21, p22, p23);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+//AnalogOut DACout(p18);
+//wave_player waver(&DACout);
 
-SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
+Mutex mut;
+ 
+// Thread 1
+// Bounce a circle around the screen centered randomly every 100ms
+void thread1(void const *args)
+{   
+    int i;
+    //int xLCD, yLCD;
+    while(true) {       // thread loop
+        mut.lock();
+        ////uLCD.baudrate(3000000);
+        ////uLCD.cls();
+        ////uLCD.color(RED);
+        ////uLCD.background_color(BLACK);
+        ////uLCD.set_font(FONT_7X8);
+        //////uLCD.text_mode(TRANSPARENT);
+        ////uLCD.text_bold(ON);
+        ////uLCD.printf("Count1: %d", i);
+        led1 = !led1;
+        mut.unlock();
+        i++;
+        
+        Thread::wait(1000);
+    }
+}
+ 
+// Thread 2
+// prints a counter to the center of the screen
+void thread2(void const *args)
+{
+    int k;
+    while(true) {       // thread loop
+        mut.lock();
+        ////uLCD.baudrate(3000000);
+        ////uLCD.cls();
+        ////uLCD.color(BLUE);
+        ////uLCD.background_color(BLACK);
+        ////uLCD.set_font(FONT_7X8);
+        //////uLCD.text_mode(TRANSPARENT);
+        ////uLCD.text_bold(ON);
+        ////uLCD.printf("Count2: %d", k);
+        led2 = !led2;
+        mut.unlock();
+        k++;
+        
+        Thread::wait(500);
+    }
+}
+ 
+//Thread 3
+//Do a "fancy" lighting effect on the RGB LED #include "ultrasonic.h"
+void thread3(void const *args)
+{
+    //mut.lock();
+    //FILE *wave_file;
+    //printf("\r\n\nHello, wave world!\n\r");
+    //Thread::wait(1000);
+    //wave_file=fopen("/sd/chirp.wav","r");
+    //if(wave_file==NULL) printf("file open error!\n\n\r");
+    //waver.play(wave_file);
+    //fclose(wave_file);
+    //mut.unlock();
+    while(true) {       // thread loop
+        led3 = !led3;
+        Thread::wait(1000);
+    }
+}
 
-AnalogOut DACout(p18);
-
-wave_player waver(&DACout);
+// Thread 4
+// Reads inputs from the bluetooth module
+//void thread4(void const *args)
+//{
+//    while(true) {       // thread loop
+//        mut.lock();
+//        myRGB.write(1.0,0.0,0.0); //red
+//        wait(2.0);
+//        myRGB.write(0.0,1.0,0.0); //green
+//        wait(2.0);
+//        myRGB.write(0.0,0.0,1.0); //blue
+//        wait(2.0);
+//        myRGB.write(1.0,0.2,0.0); //yellow = red + some green
+//        wait(2.0);
+//        //white with a slow fade to black dimming effect
+//        for (float x=1.0; x>=0.0001; x=x*0.99) {
+//            myRGB.write(x, x, x);
+//            wait(0.005);
+//        }
+//        mut.unlock();
+//        //wait(2.0);
+//        Thread::wait(1000);
+//    }
+//}
 
 int main()
 {
-    FILE *wave_file;
-    printf("\n\n\nHello, wave world!\n");
-    wave_file=fopen("/sd/sample.wav","r");
-    waver.play(wave_file);
-    fclose(wave_file);
+    Thread t1(thread1); 
+    Thread t2(thread2); 
+    Thread t3(thread3); 
+    //Thread t4(thread4);
+    //wait(0.1); // wait for uLCD ready
+
+    while(true) {       // main is the next thread
+        led4 = !led4;
+        Thread::wait(500);   // wait 0.5s
+    }
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Sat Feb 23 20:24:29 2019 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e