
Simple example. Showcase your RGB-LED using PWM for smooth transitions.
Dependencies: mbed BLE_API nRF51822
main.cpp@0:58d0b9f02eef, 2018-11-23 (annotated)
- Committer:
- larshb
- Date:
- Fri Nov 23 19:47:18 2018 +0000
- Revision:
- 0:58d0b9f02eef
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
larshb | 0:58d0b9f02eef | 1 | #include "mbed.h" |
larshb | 0:58d0b9f02eef | 2 | #include <cmath> |
larshb | 0:58d0b9f02eef | 3 | |
larshb | 0:58d0b9f02eef | 4 | PwmOut R(LED1); |
larshb | 0:58d0b9f02eef | 5 | PwmOut G(LED2); |
larshb | 0:58d0b9f02eef | 6 | PwmOut B(LED3); |
larshb | 0:58d0b9f02eef | 7 | |
larshb | 0:58d0b9f02eef | 8 | #define PI 3.14159265358979323846 |
larshb | 0:58d0b9f02eef | 9 | |
larshb | 0:58d0b9f02eef | 10 | #define MAX(a,b) a>b?a:b |
larshb | 0:58d0b9f02eef | 11 | |
larshb | 0:58d0b9f02eef | 12 | int main() { |
larshb | 0:58d0b9f02eef | 13 | float t = 0.0; |
larshb | 0:58d0b9f02eef | 14 | while(1) { |
larshb | 0:58d0b9f02eef | 15 | t+=0.01; |
larshb | 0:58d0b9f02eef | 16 | R = MAX(sin(t-0*PI/3),0); |
larshb | 0:58d0b9f02eef | 17 | G = MAX(sin(t-2*PI/3),0); |
larshb | 0:58d0b9f02eef | 18 | B = MAX(sin(t-4*PI/3),0); |
larshb | 0:58d0b9f02eef | 19 | wait(0.01); |
larshb | 0:58d0b9f02eef | 20 | } |
larshb | 0:58d0b9f02eef | 21 | } |