Simple example. Showcase your RGB-LED using PWM for smooth transitions.

Dependencies:   mbed BLE_API nRF51822

main.cpp

Committer:
larshb
Date:
2018-11-23
Revision:
0:58d0b9f02eef

File content as of revision 0:58d0b9f02eef:

#include "mbed.h"
#include <cmath>

PwmOut R(LED1);
PwmOut G(LED2);
PwmOut B(LED3);

#define PI 3.14159265358979323846

#define MAX(a,b) a>b?a:b

int main() {
    float t = 0.0;
    while(1) {
        t+=0.01;
        R = MAX(sin(t-0*PI/3),0);
        G = MAX(sin(t-2*PI/3),0);
        B = MAX(sin(t-4*PI/3),0);
        wait(0.01);
    }
}