-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
49 lines (43 loc) · 1.2 KB
/
main.cpp
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
49
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/pwm.h"
// The built in LED
#define LED_PIN 8
int main() {
stdio_init_all();
getchar_timeout_us(1);
gpio_set_function(LED_PIN, GPIO_FUNC_PWM);
uint slice_num = pwm_gpio_to_slice_num(LED_PIN);
pwm_set_wrap(slice_num, 250);
pwm_set_chan_level(slice_num, PWM_CHAN_B, 1);
pwm_set_chan_level(slice_num, PWM_CHAN_A, 1);
pwm_set_enabled(slice_num, true);
int input_char;
bool demo_mode = true;
uint i = 1;
bool up = true;
uint to_display = 0;
while (true) {
input_char = getchar_timeout_us(demo_mode ? 2000 : 10000000);
if (input_char == -1) {
if (up) {
i++;
if (i >= 250) {
up = !up;
}
} else if (!up) {
i--;
if (i <= 0) {
up = !up;
}
}
to_display = i;
demo_mode = true;
} else {
to_display = input_char;
demo_mode = false;
}
pwm_set_chan_level(slice_num, PWM_CHAN_B, to_display);
pwm_set_chan_level(slice_num, PWM_CHAN_A, to_display);
}
}