Controlling onboard RGB LED with Pulse-Width Modulation

Dependencies:   mbed C12832_lcd

Files at this revision

API Documentation at this revision

Comitter:
hulmpants
Date:
Sat Aug 17 09:43:21 2019 +0000
Parent:
0:f86c572491c3
Commit message:
Embedded Systems Laboratory 3; Controlling RGB LED with Pulse-Width Modulation;

Changed in this revision

C12832_lcd.lib Show annotated file Show diff for this revision Revisions of this file
EMB_Lab3_RGB.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show diff for this revision Revisions of this file
diff -r f86c572491c3 -r 31823a0dc268 C12832_lcd.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832_lcd.lib	Sat Aug 17 09:43:21 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/dreschpe/code/C12832_lcd/#8f86576007d6
diff -r f86c572491c3 -r 31823a0dc268 EMB_Lab3_RGB.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EMB_Lab3_RGB.cpp	Sat Aug 17 09:43:21 2019 +0000
@@ -0,0 +1,27 @@
+// IT Tralee Mechatronics: Embedded Systems LAB#3
+// Controlling RGB using PWM 
+
+#include "mbed.h"
+#include "C12832_lcd.h"
+
+C12832_LCD lcd;
+PwmOut r (p23);
+PwmOut g (p24);
+PwmOut b (p25);
+AnalogIn pot1(p19); // pot 1 = red
+AnalogIn pot2(p20); // pot 2 = green
+DigitalIn center(p14); // joystick cent = blue
+ 
+int main() {
+    while(1) {
+        r = 1 - pot1; // range=0-1 / 1=max red / levels varied by changing pot 
+        g = 1 - pot2;
+        b = 1 - center;
+        lcd.cls(); // clear LCD
+        lcd.locate(0,0); // location
+        lcd.printf("Fun RGB Rainbow Show :) \n \r");
+        lcd.locate(0,8);
+        lcd.printf("Pot 1 = %.2f", (float)pot1); // print pot value
+        lcd.locate(0,16);
+        lcd.printf("Pot 2 = %.2f", (float)pot2);    }
+}
diff -r f86c572491c3 -r 31823a0dc268 main.cpp
--- a/main.cpp	Mon Oct 15 12:19:12 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-#include "mbed.h"
-
-PwmOut r (p23);
-PwmOut g (p24);
-PwmOut b (p25);
-
-int main()
-{
-    r.period(0.001);
-    while(1) {
-        for(float i = 0.0; i < 1.0 ; i += 0.001) {
-            float p = 3 * i;
-            r = 1.0 - ((p < 1.0) ? 1.0 - p : (p > 2.0) ? p - 2.0 : 0.0);
-            g = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p);
-            b = 1.0 - ((p < 1.0) ? 0.0 : (p > 2.0) ? 3.0 - p : p - 1.0);  ;  
-            wait (0.01);
-        }
-    }
-}
\ No newline at end of file