PWM auf Pins 0 bis 20
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/cyw43_arch.h"
|
||||
#include "pwm.h"
|
||||
|
||||
// Alle 21 Kanaele synchron:
|
||||
// 500 ms Ramp-Up, 500 ms voll an, 500 ms Ramp-Down, 500 ms aus.
|
||||
static void set_all(uint16_t level) {
|
||||
for (unsigned ch = 0; ch < PWM_TOTAL_COUNT; ch++) {
|
||||
pwm_ch_set(ch, level);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
stdio_init_all();
|
||||
|
||||
if (cyw43_arch_init()) {
|
||||
printf("cyw43_arch_init fehlgeschlagen\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pwm_all_init();
|
||||
|
||||
printf("ampel: alle %u Kanaele synchron Ramp-Up / An / Ramp-Down / Aus\n",
|
||||
PWM_TOTAL_COUNT);
|
||||
|
||||
const int ramp_steps = 50;
|
||||
const int step_ms = 500 / ramp_steps;
|
||||
|
||||
while (true) {
|
||||
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, true);
|
||||
for (int i = 0; i <= ramp_steps; i++) {
|
||||
set_all((uint16_t)((i * PWM_MAX_LEVEL) / ramp_steps));
|
||||
sleep_ms(step_ms);
|
||||
}
|
||||
|
||||
set_all(PWM_MAX_LEVEL);
|
||||
sleep_ms(500);
|
||||
|
||||
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, false);
|
||||
for (int i = ramp_steps; i >= 0; i--) {
|
||||
set_all((uint16_t)((i * PWM_MAX_LEVEL) / ramp_steps));
|
||||
sleep_ms(step_ms);
|
||||
}
|
||||
|
||||
set_all(0);
|
||||
sleep_ms(500);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user