make public

Dependencies:   mbed

Revision:
0:285ec045aa05
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Mar 26 10:18:53 2021 +0000
@@ -0,0 +1,38 @@
+// Write a program to toggle the LEDs every 1 second on the application board in the following order repeatedly. 
+// GREEN  -> RED  -> BLUE  -> ALL OFF 
+#include "mbed.h"
+
+DigitalOut R(p23); //Red pin of RGB LED
+DigitalOut G(p24); //Green pin of RGB LED
+DigitalOut B(p25); //Blue pin of RGB LED
+int t = 1; // initialise a variable of type int, as a time, 1 sec.
+//*NOTE THE RGB LED on the application board is "0" for on, "1" for off * NOTE //      
+void r(){ // led function red on
+       R = 0, G = B = 1;
+       wait(t); // takes the value from the int above - makes system wide change easier as changing the value in int t will apply to all fucntions.
+   }
+void g(){ // led function green on
+       G = 0, R = B = 1;
+       wait (t);
+   }
+   
+void b(){ // led function blue on
+       B = 0, R = G = 1;
+       wait (t);  
+   }
+   
+   void o(){ // led function all off
+       B =  R = G = 1;
+       wait (t);  
+   }
+int main() { // main program, will use this to call up the led functions.
+    R = G = B = 1; // init led to off on start up
+
+    while(1) { // do forever 
+      g(); // call the colour functions in the order specified in the question.
+      r();
+      b();
+      o();
+                
+    }
+}