const PWM = require("rpio-pwm"); let pwmCh, stepNum = 500, refresh = 50, pinBoardCode = 18 console.log("初始化 PWM 通道"); PWM.set_log_level(PWM.logLevel.debug); const cycleTimeUs = (1000 / refresh) * 1000, stepTimeUs = cycleTimeUs / stepNum, steeringPWMCfg = { cycle_time_us: cycleTimeUs, step_time_us: stepTimeUs, delay_hw: 1, }; pwmCh = PWM.create_dma_channel( PWM.host_is_model_pi4() ? 5 : 12, steeringPWMCfg ); const pin = pwmCh.create_pwm(pinBoardCode); pin.set_width((256 / 100) * stepNum); setTimeout(function () { // it's good idea to cleanup before exit. console.log('clear'); pwmCh.shutdown(); }, 2000);