Show Flashing RGB LED Interrupted by two keys two turn on green and blue LEDs on the AZ3166

Files at this revision

API Documentation at this revision

Comitter:
appa
Date:
Thu Feb 04 16:41:22 2021 +0000
Commit message:
Flashing Random RGB LED interrupt with buttons

Changed in this revision

RPinName.h 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-os.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RPinName.h	Thu Feb 04 16:41:22 2021 +0000
@@ -0,0 +1,10 @@
+PinName led1 = PB_2;
+PinName led2 = PA_15;
+PinName led3 = PC_13;
+PinName RedRGB = PB_4;
+PinName GreenRGB = PB_3;
+PinName BlueRGB = PC_7;
+PinName tx = PA_11;
+PinName rx = PA_12;
+PinName Key2 = PA_4;
+PinName Key3 = PA_10;
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Feb 04 16:41:22 2021 +0000
@@ -0,0 +1,57 @@
+#include "mbed.h"
+#include "platform/mbed_thread.h"
+#include "RPinName.h"
+
+// Blinking rate in milliseconds
+#define loopdelay    1000
+#define betweenleds 500
+ // Initialise the digital pins for LEDs as an output
+    DigitalOut ledg(led1);  // WiFi or same as LED1
+    DigitalOut ledb(led2);  // Azure
+    DigitalOut ledy(led3);  // User
+    
+    InterruptIn ButtonA(Key2);
+    InterruptIn ButtonB(Key3);
+    
+    // Initialise the pulse-width-moudulation for RGB LED
+    PwmOut RGBR(RedRGB);
+    PwmOut RGBG(GreenRGB);
+    PwmOut RGBB(BlueRGB);
+    
+    Serial AZ(tx, rx); // tx, rx
+    
+    void ToggleGreen()
+    {
+        ledg = !ledg;
+        }
+    void ToggleBlue()
+    {
+        ledb = !ledb;
+        }
+
+int main()
+{
+    //ButtonA.rise(&ToggleGreen);
+    //ButtonB.rise(&ToggleBlue);
+    ButtonA.mode(PullUp);
+    ButtonA.fall(&ToggleGreen);
+    ButtonB.mode(PullUp);
+    ButtonB.fall(&ToggleBlue);
+    
+    while(1) {
+        
+        AZ.printf("Hi There from Appa\r\n");
+        RGBR = 0;
+        AZ.printf("Random Green RGB LED\r\n");
+        RGBG = rand() % 100;
+        thread_sleep_for(betweenleds);
+        RGBG = 0;
+        AZ.printf("Random Blue RGB LED\r\n");
+        RGBB = rand() % 100;
+        thread_sleep_for(betweenleds);
+        RGBB = 0;
+        AZ.printf("Random Red RGB LED\r\n");
+        RGBR = rand() % 100;
+        thread_sleep_for(loopdelay);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Thu Feb 04 16:41:22 2021 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#cf4f12a123c05fcae83fc56d76442015cb8a39e9