Dar Leg / Mbed OS RGBLedInterrupt
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "platform/mbed_thread.h"
00003 #include "RPinName.h"
00004 
00005 // Blinking rate in milliseconds
00006 #define loopdelay    1000
00007 #define betweenleds 500
00008  // Initialise the digital pins for LEDs as an output
00009     DigitalOut ledg(led1);  // WiFi or same as LED1
00010     DigitalOut ledb(led2);  // Azure
00011     DigitalOut ledy(led3);  // User
00012     
00013     InterruptIn ButtonA(Key2);
00014     InterruptIn ButtonB(Key3);
00015     
00016     // Initialise the pulse-width-moudulation for RGB LED
00017     PwmOut RGBR(RedRGB);
00018     PwmOut RGBG(GreenRGB);
00019     PwmOut RGBB(BlueRGB);
00020     
00021     Serial AZ(tx, rx); // tx, rx
00022     
00023     void ToggleGreen()
00024     {
00025         ledg = !ledg;
00026         }
00027     void ToggleBlue()
00028     {
00029         ledb = !ledb;
00030         }
00031 
00032 int main()
00033 {
00034     //ButtonA.rise(&ToggleGreen);
00035     //ButtonB.rise(&ToggleBlue);
00036     ButtonA.mode(PullUp);
00037     ButtonA.fall(&ToggleGreen);
00038     ButtonB.mode(PullUp);
00039     ButtonB.fall(&ToggleBlue);
00040     
00041     while(1) {
00042         
00043         AZ.printf("Hi There from Appa\r\n");
00044         RGBR = 0;
00045         AZ.printf("Random Green RGB LED\r\n");
00046         RGBG = rand() % 100;
00047         thread_sleep_for(betweenleds);
00048         RGBG = 0;
00049         AZ.printf("Random Blue RGB LED\r\n");
00050         RGBB = rand() % 100;
00051         thread_sleep_for(betweenleds);
00052         RGBB = 0;
00053         AZ.printf("Random Red RGB LED\r\n");
00054         RGBR = rand() % 100;
00055         thread_sleep_for(loopdelay);
00056     }
00057 }