ayy we can remote control an LED

This commit is contained in:
embr 2023-04-25 14:47:56 +02:00
parent a91462d6db
commit 792d00bc05
4 changed files with 19 additions and 5 deletions

View file

@ -26,6 +26,7 @@ target_link_libraries(vibe-check
pico_cyw43_arch_none
pico_btstack_ble
pico_btstack_cyw43
hardware_pwm
)
pico_btstack_make_gatt_header(vibe-check PRIVATE "${CMAKE_SOURCE_DIR}/src/vibe.gatt")

View file

@ -41,7 +41,6 @@ int main() {
// set initial state
state_init();
state_set_power(0);
att_server_init(profile_data, bt_att_read_callback, bt_att_write_callback);

View file

@ -1,10 +1,24 @@
#include "state.h"
#include "hardware/pwm.h"
#include "pico/stdlib.h"
#define PWM_PIN_0 16
#define PWM_PIN_1 17
static int pwm_slice = 0;
void state_init() {
// TODO: Assign GPIO pins to PWM.
pwm_slice = pwm_gpio_to_slice_num(PWM_PIN_0);
gpio_set_function(PWM_PIN_0, GPIO_FUNC_PWM);
gpio_set_function(PWM_PIN_1, GPIO_FUNC_PWM);
pwm_set_wrap(pwm_slice, 99);
state_set_power(0);
pwm_set_enabled(pwm_slice, true);
}
void state_set_power(uint8_t power) {
// TODO: Set power!
pwm_set_chan_level(pwm_slice, PWM_CHAN_A, power);
pwm_set_chan_level(pwm_slice, PWM_CHAN_B, power);
}

View file

@ -3,10 +3,10 @@
#include <stdint.h>
// Initializes wand state.
// Initialize wand state.
void state_init();
// Sets the wand's power, 0-100.
// Set the wand's power, 0-100.
void state_set_power(uint8_t power);
#endif