wordpress建站需要多大内存,易语言做购物网站,在线免费网页代理,电商创客网站建设方案香橙派或者树莓派 等开发板#xff0c;本身带有硬件PWM,比如香橙派3 lts版#xff0c;但是这个引脚不符合我的项目需求#xff0c;我需要外接一个电机#xff0c;在检测到人脸的时候 转动#xff0c;但是这个硬件引脚#xff0c;只要上电就开始输出pwm 信号#xff0c;导…香橙派或者树莓派 等开发板本身带有硬件PWM,比如香橙派3 lts版但是这个引脚不符合我的项目需求我需要外接一个电机在检测到人脸的时候 转动但是这个硬件引脚只要上电就开始输出pwm 信号导致电机一直再转因此采用软件 利用GPIO模拟的方式更符合需求。 #pragma once
#include wiringPi.h
#include softPwm.h
#include stdio.h
#include stdlib.h
#include stdint.h
#include memory
#include Util/logger.husing namespace toolkit;
const int gpioPin 10; //GPIO引脚
const int pwmRange 100; // PWM范围0-100对应占空比0-100%
const int targetDutyCycle 80; // 目标占空比0-100class Vibration : public std::enable_shared_from_thisVibration
{
public:using Ptr std::shared_ptrVibration;~Vibration(){}bool init(){// 初始化 WiringPi 库if (wiringPiSetup() -1){ErrorL WiringPi初始化失败;return false;}// 初始化软件PWM参数引脚、初始值、范围if (softPwmCreate(gpioPin, 0, pwmRange) ! 0){ErrorL 软件PWM初始化失败;return false;}return true;}void vibrate(){// 设置占空比softPwmWrite(gpioPin, targetDutyCycle);InfoL PWM运行中 (引脚 gpioPin ), 占空比: targetDutyCycle % ;// 保持运行例如5秒delay(3000);// 停止PWMsoftPwmWrite(gpioPin, 0);}
};