58 lines
1.2 KiB
C
58 lines
1.2 KiB
C
#include "hardware/gpio.h"
|
|
#include "hardware/pwm.h"
|
|
//#include <stdio.h>
|
|
#include <pico/stdlib.h>
|
|
|
|
#define LEDY_PIN 13
|
|
#define LEDG_PIN 14
|
|
#define LEDR_PIN 15
|
|
|
|
#define POWER_SWITCH_PIN 10
|
|
|
|
int main()
|
|
{
|
|
//stdio_init_all();
|
|
//printf("Hello, world!\n");
|
|
|
|
bool power_switch_state = false;
|
|
|
|
gpio_init(LEDY_PIN);
|
|
gpio_init(LEDG_PIN);
|
|
gpio_init(LEDR_PIN);
|
|
|
|
gpio_set_dir(LEDY_PIN, true);
|
|
gpio_set_dir(LEDG_PIN, true);
|
|
gpio_set_dir(LEDR_PIN, true);
|
|
|
|
gpio_put(LEDY_PIN, true);
|
|
gpio_put(LEDG_PIN, true);
|
|
gpio_put(LEDR_PIN, true);
|
|
|
|
// set up PWM for 50 kHz @ 512 steps resolution
|
|
uint slice_num = pwm_gpio_to_slice_num(POWER_SWITCH_PIN);
|
|
|
|
pwm_set_clkdiv_int_frac(slice_num, 4, (88 << 4) / 100);
|
|
gpio_set_function(POWER_SWITCH_PIN, GPIO_FUNC_PWM);
|
|
pwm_set_wrap(slice_num, 512);
|
|
pwm_set_chan_level(slice_num, PWM_CHAN_A, 410);
|
|
pwm_set_enabled(slice_num, true);
|
|
|
|
sleep_ms(3000);
|
|
|
|
gpio_put(LEDY_PIN, false);
|
|
gpio_put(LEDG_PIN, false);
|
|
|
|
while (true) {
|
|
gpio_put(LEDR_PIN, true);
|
|
gpio_put(LEDG_PIN, false);
|
|
sleep_ms(500);
|
|
gpio_put(LEDY_PIN, true);
|
|
gpio_put(LEDR_PIN, false);
|
|
sleep_ms(500);
|
|
gpio_put(LEDY_PIN, false);
|
|
gpio_put(LEDG_PIN, true);
|
|
sleep_ms(500);
|
|
}
|
|
return 0;
|
|
}
|