蛍とかキー入力とかなんとかこれで動いた。
Cのコード
#include "pico/stdlib.h"
#include "hardware/pwm.h"
int main() {
#ifndef PICO_DEFAULT_LED_PIN
#warning blink example requires a board with a regular LED
#else
const uint LED_PIN = 22;
const uint LED_PIN1 = 25;
const uint input_PIN = 20;
gpio_init(input_PIN);
gpio_set_dir(input_PIN, GPIO_IN);
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
gpio_set_function(LED_PIN, GPIO_FUNC_PWM);
gpio_init(LED_PIN1);
gpio_set_dir(LED_PIN1, GPIO_OUT);
gpio_put(LED_PIN1, 1);
uint slice_num = pwm_gpio_to_slice_num(22); //pin 22 slice No = 22
/*例えばPWM周波数を1KHzに、PWMの分解能を8ビット(0~255)に設定したい場合、
sysclock = 125,000,000Hz、wrap = 255、f=1000Hz より
clkdiv = sysclock / ((wrap+1) ⋅ f )
分周比 clkdiv = 488.2812 となる。*/
pwm_set_clkdiv(slice_num, 488.2812);
pwm_set_wrap(slice_num, 255);
// チャンネルPWMのHigh期間を設定
//pwm_set_chan_level(slice_num, 0, 5);
//pwm_set_enabled(slice_num, true);
int i=0;
int flag=0;
int flaga=0;
while (true) {
if(gpio_get(input_PIN) == 0)
{
gpio_put(LED_PIN1, 0);
flaga=0;
while(flaga<3){
if(flag==0){
i=i+1;
if(i==256) flag=1;
else ;
}
else if(flag==1) {
sleep_ms(500);
flag=2;
}
else if(flag==2) {
i=i-1;
if(i==0) flag=3;
else ;
}
else
{
sleep_ms(1000);
flag=0;
i=0;
flaga=flaga+1;
}
pwm_set_chan_level(slice_num, 0, i);
pwm_set_enabled(slice_num, true);
sleep_ms(10);
//pwm_set_enabled(slice_num, false);
}
gpio_put(LED_PIN1, 1);
}
else;
#endif
}
}
Makeがこちら
# Generated Cmake Pico project file
cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Initialise pico_sdk from installed location
# (note this can come from environment, CMake cache etc)
# == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work ==
if(WIN32)
set(USERHOME $ENV{USERPROFILE})
else()
set(USERHOME $ENV{HOME})
endif()
set(sdkVersion 2.1.1)
set(toolchainVersion 14_2_Rel1)
set(picotoolVersion 2.1.1)
set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake)
if (EXISTS ${picoVscode})
include(${picoVscode})
endif()
# ====================================================================================
set(PICO_BOARD pico CACHE STRING "Board type")
# Pull in Raspberry Pi Pico SDK (must be before project)
include(pico_sdk_import.cmake)
project(hotal2 C CXX ASM)
# Initialise the Raspberry Pi Pico SDK
pico_sdk_init()
# Add executable. Default name is the project name, version 0.1
add_executable(hotal2 hotal2.c )
pico_set_program_name(hotal2 "hotal2")
pico_set_program_version(hotal2 "0.1")
# Modify the below lines to enable/disable output over UART/USB
pico_enable_stdio_uart(hotal2 0)
pico_enable_stdio_usb(hotal2 0)
# Add the standard library to the build
target_link_libraries(hotal2
pico_stdlib)
# Add the standard include files to the build
target_include_directories(hotal2 PRIVATE
${CMAKE_CURRENT_LIST_DIR}
)
# Pull in our pico_stdlib which pulls in commonly used features
target_link_libraries(hotal2 pico_stdlib hardware_pwm)
pico_add_extra_outputs(hotal2)