官术网_书友最值得收藏!

The softPWM library

wiringPi consists of a softPWM library, using which we can get PWM signal output from any data pin of the RPi. The softPWM library contains two main functions: softPwmCreate and softPwmWrite. Both of these functions work as follows:

softPwmCreate(pin number, initial duty cycle value, max duty cycle value);

The softPwmCreate function is used to create a PWM pin. It consists of three main parameters:

  • pin number: Pin number represents the wiringPi pin that we want to set as a PWM pin.
  • initial duty cycle value: In initial duty cycle value we have to provide as the minimum value of the duty cycle. The initial duty cycle value is ideally set to 0.
  • max duty cycle valueIn the max duty cycle value, we have to provide the maximum value of the duty cycle. This value must be set to 100:
softPwmWrite(pin number, duty cycle value);

The softPwmWrite function is used to write PWM data on the output device (for example, LED). It consists of two parameters:

  • pin number: Pin number represents the wiringPi pin on which we have to write the PWM data. 
  • duty cycle value: In this parameter, we have to provide the duty cycle value. The duty cycle value must be between the initial duty cycle value and max duty cycle value, that is, in the range of 0 to 100.

Now that we understand the two functions inside the softPWM library, we will write a simple C++ program to make an LED blink at different intensities. 

主站蜘蛛池模板: 勃利县| 延长县| 大田县| 霸州市| 垣曲县| 若羌县| 德格县| 仁怀市| 镇雄县| 伊川县| 栾城县| 南部县| 赤峰市| 莆田市| 子长县| 宜黄县| 永昌县| 茌平县| 冕宁县| 昌平区| 边坝县| 扶风县| 蓬莱市| 衡阳市| 石棉县| 米林县| 科尔| 永和县| 阜宁县| 赤壁市| 贡觉县| 越西县| 阳山县| 鄂温| 德兴市| 深圳市| 溧阳市| 长乐市| 襄城县| 开封市| 平度市|