Coolpi PWM
-
任何人都可以解释如何在 coolpi 上使用 PWM 吗?
-
@macthree 有部分GPIO支持硬件PWM功能,当然也可以用GPIO模拟PWM功能。
-
使用 raspberry pi wiring.h 需要包含访问 PWM,如下所示.
coolpi 需要包括什么?C Program
/*
Change the Intensity of LED using PWM on Raspberry Pi
http://www.electronicwings.com
*/#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>const int PWM_pin = 1; /* GPIO 1 as per WiringPi, GPIO18 as per BCM */
int main (void)
{
int intensity ;if (wiringPiSetup () == -1)
exit (1) ;pinMode (PWM_pin, PWM_OUTPUT) ; /* set PWM pin as output */
while (1)
{for (intensity = 0 ; intensity < 1024 ; ++intensity) { pwmWrite (PWM_pin, intensity) ; /* provide PWM value for duty cycle */ delay (1) ; } delay(1); for (intensity = 1023 ; intensity >= 0 ; --intensity) { pwmWrite (PWM_pin, intensity) ; delay (1) ; } delay(1);
}
} -
@macthree
这是软PWM,需要重写封装WiringPi -