-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab1.5.cpp
More file actions
48 lines (34 loc) · 858 Bytes
/
lab1.5.cpp
File metadata and controls
48 lines (34 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "mbed.h"
#include "ledutils.h"
DigitalOut led1(LED1);
RawSerial serial(SERIAL_TX, SERIAL_RX, 115200);
// Replace pin assignments if different
PwmOut ledR(D9);
PwmOut ledG(D11);
PwmOut ledB(D12);
DigitalIn btn(D8, PullUp);
int main() {
serial.puts("\r\n\r\n" __FILE__ ", built " __DATE__ " " __TIME__ "\r\n");
ledR.period_us(500);
ledG.period_us(500);
ledB.period_us(500);
float hue = 0;
while (true) {
hue += 0.05;
float r, g, b;
hsv_to_rgb_float(hue, 1, 1, &r, &g, &b);
// Square intensity to account for human perceived brightness.
r = r * r;
g = g * g;
b = b * b;
// Invert polarity to account for common-anode LED (emits light when pin is low).
r = 1 - r;
g = 1 - g;
b = 1 - b;
// Set outputs.
ledR = r;
ledG = g;
ledB = b;
wait_us(1000000 / 2400);
}
}