需要器件led等一只,500欧姆电阻一个, 树莓派一个
接法pin1 -> led->电阻->接地
脚本
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main (void)
{
int bright ;
printf ("Raspberry Pi wiringPi PWM test program\n") ;
if (wiringPiSetup () == -1)
exit (1) ;
pinMode (1, PWM_OUTPUT) ;
for (;;)
{//pwm以毫秒为单位由0增到1024
for (bright = 0 ; bright < 1024 ; ++bright)
{
pwmWrite (1, bright) ;
delay (1) ;
}
//pwm以毫秒为单位由1023减到0
for (bright = 1023 ; bright >= 0 ; --bright)
{
pwmWrite (1, bright) ;
delay (1) ;
}
}
return 0 ;
}
|